opensearch-project / opensearch-project/sql

[BUG] REGEXP filter failed due to IllegalStateException

Open
#2,796 0 comments 0 reactions 1 assignee View on GitHub

@qianheng-aws is already working on this.

Since Jun 27, 2025.

bug SQL
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:

  1. create an index with the following mappings:
{
  "mappings": {
    "properties": {
      "field1": {
        "type": "keyword"
      }
    }
  }
}
  1. write one doc using bulk API:
{"index": {"_id": 1}}
{"field1": "test search something"}
  1. 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:

https://github.com/opensearch-project/sql/blob/43263963aca2ada949d55ae01cd38788d5d96fbb/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScript.java#L51-L57

but what OperatorUtils#matchesRegexp returns is an integer value:

https://github.com/opensearch-project/sql/blob/43263963aca2ada949d55ae01cd38788d5d96fbb/core/src/main/java/org/opensearch/sql/utils/OperatorUtils.java#L37-L40

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.