opensearch-project / opensearch-project/sql
[BUG] REGEXP filter failed due to IllegalStateException
@qianheng-aws is already working on this.
Since Jun 27, 2025.
- Dominant language
- Java
- Stars
- 176
- Forks
- 229
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 43
Description
What is the bug?
When executing a SQL query with REGEXP filter, get the following exception:
{
"error": {
"reason": "Error occurred in OpenSearch engine: all shards failed",
"details": "Shard[0]: java.lang.IllegalStateException: Expression has wrong result type instead of boolean: expression [regexp(field1, \"test.*\")], result [1]\n\nFor more details, please send request for Json format to see the raw response from OpenSearch engine.",
"type": "SearchPhaseExecutionException"
},
"status": 500
}
How can one reproduce the bug?
Steps to reproduce the behavior:
- create an index with the following mappings:
{
"mappings": {
"properties": {
"field1": {
"type": "keyword"
}
}
}
}
- write one doc using bulk API:
{"index": {"_id": 1}}
{"field1": "test search something"}
- run the following SQL query:
{
"query": "SELECT field1 FROM test WHERE field1 REGEXP 'test.*'"
}
Do you have any additional context?
The root cause of this bug may be because what ExpressionFilterScript#evaluateExpression expects is a boolean value:
but what OperatorUtils#matchesRegexp returns is an integer value:
If we modify the return type of OperatorUtils#matchesRegexp, it will impact the return type of the REGEXP function, which could be a breaking change. To avoid this, we could consider converting the integer value to a boolean value in ExpressionFilterScript#evaluateExpression.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.