Skip to content

[BUG] PPL where command does not work as expected. #5054

Closed

Description

@penghuo

What is the bug?
PPL query include where command throw unexpected exception

{
  "error": {
    "reason": "Error occurred in OpenSearch engine: all shards failed",
    "details": "Shard[0]: [test/LI_vgiDbRJ6XzIAwO1uWtw] QueryShardException[failed to create query: Failed to compile inline script [{\"langType\":\"calcite\",\"script\":\"rO0ABXQEoXsKICAib3AiOiB7CiAgICAibmFtZSI6ICJBTkQiLAogICAgImtpbmQiOiAiQU5EIiwKICAgICJzeW50YXgiOiAiQklOQVJZIgogIH0sCiAgIm9wZXJhbmRzIjogWwogICAgewogICAgICAiZHluYW1pY1BhcmFtIjogMCwKICAgICAgInR5cGUiOiB7CiAgICAgICAgInR5cGUiOiAiQk9PTEVBTiIsCiAgICAgICAgIm51bGxhYmxlIjogdHJ1ZQogICAgICB9CiAgICB9LAogICAgewogICAgICAib3AiOiB7CiAgICAgICAgIm5hbWUiOiAicXVlcnlfc3RyaW5nIiwKICAgICAgICAia2luZCI6ICJPVEhFUl9GVU5DVElPTiIsCiAgICAgICAgInN5bnRheCI6ICJGVU5DVElPTiIKICAgICAgfSwKICAgICAgIm9wZXJhbmRzIjogWwogICAgICAgIHsKICAgICAgICAgICJvcCI6IHsKICAgICAgICAgICAgIm5hbWUiOiAiTUFQIiwKICAgICAgICAgICAgImtpbmQiOiAiTUFQX1ZBTFVFX0NPTlNUUlVDVE9SIiwKICAgICAgICAgICAgInN5bnRheCI6ICJTUEVDSUFMIgogICAgICAgICAgfSwKICAgICAgICAgICJvcGVyYW5kcyI6IFsKICAgICAgICAgICAgewogICAgICAgICAgICAgICJkeW5hbWljUGFyYW0iOiAxLAogICAgICAgICAgICAgICJ0eXBlIjogewogICAgICAgICAgICAgICAgInR5cGUiOiAiVkFSQ0hBUiIsCiAgICAgICAgICAgICAgICAibnVsbGFibGUiOiB0cnVlLAogICAgICAgICAgICAgICAgInByZWNpc2lvbiI6IC0xCiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgImR5bmFtaWNQYXJhbSI6IDIsCiAgICAgICAgICAgICAgInR5cGUiOiB7CiAgICAgICAgICAgICAgICAidHlwZSI6ICJWQVJDSEFSIiwKICAgICAgICAgICAgICAgICJudWxsYWJsZSI6IHRydWUsCiAgICAgICAgICAgICAgICAicHJlY2lzaW9uIjogLTEKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIF0KICAgICAgICB9CiAgICAgIF0sCiAgICAgICJjbGFzcyI6ICJvcmcub3BlbnNlYXJjaC5zcWwuZXhwcmVzc2lvbi5mdW5jdGlvbi5Vc2VyRGVmaW5lZEZ1bmN0aW9uQnVpbGRlciQxIiwKICAgICAgInR5cGUiOiB7CiAgICAgICAgInR5cGUiOiAiQk9PTEVBTiIsCiAgICAgICAgIm51bGxhYmxlIjogZmFsc2UKICAgICAgfSwKICAgICAgImRldGVybWluaXN0aWMiOiBmYWxzZSwKICAgICAgImR5bmFtaWMiOiBmYWxzZQogICAgfQogIF0KfQ==\"}] using lang [opensearch_compounded_script]]; nested: GeneralScriptException[Failed to compile inline script [{\"langType\":\"calcite\",\"script\":\"rO0ABXQEoXsKICAib3AiOiB7CiAgICAibmFtZSI6ICJBTkQiLAogICAgImtpbmQiOiAiQU5EIiwKICAgICJzeW50YXgiOiAiQklOQVJZIgogIH0sCiAgIm9wZXJhbmRzIjogWwogICAgewogICAgICAiZHluYW1pY1BhcmFtIjogMCwKICAgICAgInR5cGUiOiB7CiAgICAgICAgInR5cGUiOiAiQk9PTEVBTiIsCiAgICAgICAgIm51bGxhYmxlIjogdHJ1ZQogICAgICB9CiAgICB9LAogICAgewogICAgICAib3AiOiB7CiAgICAgICAgIm5hbWUiOiAicXVlcnlfc3RyaW5nIiwKICAgICAgICAia2luZCI6ICJPVEhFUl9GVU5DVElPTiIsCiAgICAgICAgInN5bnRheCI6ICJGVU5DVElPTiIKICAgICAgfSwKICAgICAgIm9wZXJhbmRzIjogWwogICAgICAgIHsKICAgICAgICAgICJvcCI6IHsKICAgICAgICAgICAgIm5hbWUiOiAiTUFQIiwKICAgICAgICAgICAgImtpbmQiOiAiTUFQX1ZBTFVFX0NPTlNUUlVDVE9SIiwKICAgICAgICAgICAgInN5bnRheCI6ICJTUEVDSUFMIgogICAgICAgICAgfSwKICAgICAgICAgICJvcGVyYW5kcyI6IFsKICAgICAgICAgICAgewogICAgICAgICAgICAgICJkeW5hbWljUGFyYW0iOiAxLAogICAgICAgICAgICAgICJ0eXBlIjogewogICAgICAgICAgICAgICAgInR5cGUiOiAiVkFSQ0hBUiIsCiAgICAgICAgICAgICAgICAibnVsbGFibGUiOiB0cnVlLAogICAgICAgICAgICAgICAgInByZWNpc2lvbiI6IC0xCiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgImR5bmFtaWNQYXJhbSI6IDIsCiAgICAgICAgICAgICAgInR5cGUiOiB7CiAgICAgICAgICAgICAgICAidHlwZSI6ICJWQVJDSEFSIiwKICAgICAgICAgICAgICAgICJudWxsYWJsZSI6IHRydWUsCiAgICAgICAgICAgICAgICAicHJlY2lzaW9uIjogLTEKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIF0KICAgICAgICB9CiAgICAgIF0sCiAgICAgICJjbGFzcyI6ICJvcmcub3BlbnNlYXJjaC5zcWwuZXhwcmVzc2lvbi5mdW5jdGlvbi5Vc2VyRGVmaW5lZEZ1bmN0aW9uQnVpbGRlciQxIiwKICAgICAgInR5cGUiOiB7CiAgICAgICAgInR5cGUiOiAiQk9PTEVBTiIsCiAgICAgICAgIm51bGxhYmxlIjogZmFsc2UKICAgICAgfSwKICAgICAgImRldGVybWluaXN0aWMiOiBmYWxzZSwKICAgICAgImR5bmFtaWMiOiBmYWxzZQogICAgfQogIF0KfQ==\"}] using lang [opensearch_compounded_script]]; nested: UnsupportedOperationException[Relevance search query functions are only supported when they are pushed down];\n\nFor more details, please send request for Json format to see the raw response from OpenSearch engine.",
    "type": "SearchPhaseExecutionException"
  },
  "status": 400
}

How can one reproduce the bug?

###
PUT {{baseUrl}}/test
Content-Type: application/x-ndjson

{
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "url": {
        "type": "text"
      },
      "is_internal": {
        "type": "boolean"
      }
    }
  }
}

###
POST {{baseUrl}}/test/_bulk
Content-Type: application/x-ndjson

{"index": {}}
{"@timestamp":"2025-08-19T04:51:24Z", "url": "http"}
{"index": {}}
{"@timestamp":"2025-08-19T04:51:24Z", "url": "http", "is_internal": true}
{"index": {}}
{"@timestamp":"2025-08-19T04:51:24Z", "url": "http", "is_internal": false}

###
POST {{baseUrl}}/_plugins/_ppl/
Content-Type: application/x-ndjson

{
    "query": "source=test url=http | where is_internal=true"
}

What is the expected behavior?
return correctly

What is your host/environment?

Activity

  1. added
    bug
    PPL
    on Jan 16, 2026
  2. songkant-aws commented on Jan 19, 2026

    @songkant-aws
    Collaborator

    Let me take a look

  3. songkant-aws commented on Jan 26, 2026

    @songkant-aws
    Collaborator

    The type of "is_internal" field in the index mapping is BOOLEAN. Since it's already a BOOLEAN type, Calcite simplifies the expression condition from EQUAL(is_internal, true) to FIELD(is_internal). It's no longer a regular expression.

    The goal of this query is to push down this expression AND(query_string(), FIELD(is_internal)) to scan. Our pushdown PredicateAnalyzer won't treat a FIELD(is_internal) as regular expression. So the analyzed expression list will place NULL at that place, causing PredicateAnalyzer throws NPE while generating DSL query blob. This triggers a fallback mechanism to wrap this condition expression as script but our script can't execute the search relevance function. Instead, it should be a pure DSL query that combines the two operands using a logical AND.

    I think we may need to support this case in pushdown PredicateAnalyzer.

  4. qianheng-aws commented on Jan 27, 2026

    @qianheng-aws
    Collaborator

    @songkant-aws Both below queries can work. But combining these 2 filter conditions together induces the above exception.

    source=test url=http
    
    source=test  | where is_internal=true
    

    The query "source=test url=http | where is_internal=true" will produce a script for SCRIPT->AND(query_string(MAP('query', 'url:http':VARCHAR)), $0) while query_string function is not supported in our script.

  5. songkant-aws commented on Jan 27, 2026

    @songkant-aws
    Collaborator

    @qianheng-aws Yes, that's what I have observed in PredicateAnalyzer. The current andOr only evaluates non-field expressions. So it fallbacks to script, which throws exception at execution runtime

  6. penghuo commented on Feb 3, 2026

    @penghuo
    CollaboratorAuthor

    Another pushdown releated issue, I expect bool field should rewrite as DSL term query instead of script query.

    ###
    POST {{baseUrl}}/_plugins/_ppl/_explain?format=yaml
    Content-Type: application/x-ndjson
    
    {
        "query": "source=test | where is_internal=true"
    }
    
    • response
    calcite:
      logical: |
        LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
          LogicalProject(is_internal=[$0], url=[$1], @timestamp=[$2])
            LogicalFilter(condition=[$0])
              CalciteLogicalIndexScan(table=[[OpenSearch, test]])
      physical: |
        CalciteEnumerableIndexScan(table=[[OpenSearch, test]], PushDownContext=[[PROJECT->[is_internal, url, @timestamp], SCRIPT->$0, LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"script":{"script":{"source":"{\"langType\":\"calcite\",\"script\":\"rO0ABXQAVHsKICAiZHluYW1pY1BhcmFtIjogMCwKICAidHlwZSI6IHsKICAgICJ0eXBlIjogIkJPT0xFQU4iLAogICAgIm51bGxhYmxlIjogdHJ1ZQogIH0KfQ==\"}","lang":"opensearch_compounded_script","params":{"utcTimestamp":1770083101590655000,"SOURCES":[0],"DIGESTS":["is_internal"]}},"boost":1.0}},"_source":{"includes":["is_internal","url","@timestamp"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)])
    
  7. songkant-aws commented on Feb 3, 2026

    @songkant-aws
    Collaborator

    @penghuo It has similar root cause with original issue in description. The bug fix PR also addresses this issue. I have added several more explain test cases in the PR #5071

  8. moved this from Not Started to Done in PPL Trackeron Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLbug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions