Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plain highlighter throws UOE when using a script_score query wrapping an exists query #99700

Closed
romseygeek opened this issue Sep 20, 2023 · 1 comment · Fixed by #99804
Closed
Assignees
Labels
>bug :Search/Highlighting How a query matched a document Team:Search Meta label for search team

Comments

@romseygeek
Copy link
Contributor

Elasticsearch Version

8.10

Installed Plugins

No response

Java Version

bundled

OS Version

unix

Problem Description

If you try and highlight a script_score query that further wraps an exists query using the plain highlighter, you get a stack trace that looks like this:

Caused by: java.lang.UnsupportedOperationException
	at org.apache.lucene.search.highlight.WeightedSpanTermExtractor$DelegatingLeafReader.getFieldInfos(WeightedSpanTermExtractor.java:463) ~[lucene-highlighter-9.6.0.jar:?]
	at org.apache.lucene.search.FieldExistsQuery.rewrite(FieldExistsQuery.java:116) ~[lucene-core-9.6.0.jar:?]
	at org.apache.lucene.search.ConstantScoreQuery.rewrite(ConstantScoreQuery.java:44) ~[lucene-core-9.6.0.jar:?]
	at org.apache.lucene.search.ConstantScoreQuery.rewrite(ConstantScoreQuery.java:44) ~[lucene-core-9.6.0.jar:?]
	at org.apache.lucene.search.BooleanQuery.rewrite(BooleanQuery.java:289) ~[lucene-core-9.6.0.jar:?]
	at org.elasticsearch.common.lucene.search.function.ScriptScoreQuery.rewrite(ScriptScoreQuery.java:73) ~[elasticsearch-8.8.2.jar:?]
	at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.extract(WeightedSpanTermExtractor.java:253) ~[lucene-highlighter-9.6.0.jar:?]
	at org.elasticsearch.search.fetch.subphase.highlight.CustomQueryScorer$CustomWeightedSpanTermExtractor.extract(CustomQueryScorer.java:77) ~[elasticsearch-8.8.2.jar:?]
	at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.getWeightedSpanTerms(WeightedSpanTermExtractor.java:533) ~[lucene-highlighter-9.6.0.jar:?]
	at org.apache.lucene.search.highlight.QueryScorer.initExtractor(QueryScorer.java:209) ~[lucene-highlighter-9.6.0.jar:?]
	at org.apache.lucene.search.highlight.QueryScorer.init(QueryScorer.java:178) ~[lucene-highlighter-9.6.0.jar:?]
	at org.apache.lucene.search.highlight.Highlighter.getBestTextFragments(Highlighter.java:173) ~[lucene-highlighter-9.6.0.jar:?]
	at org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter.highlight(PlainHighlighter.java:151) ~[elasticsearch-8.8.2.jar:?]
	at org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase$1.process(HighlightPhase.java:69) ~[elasticsearch-8.8.2.jar:?]

Related to #92919, but as ScriptScoreQuery is an elasticsearch query we need to extend CustomWeightedSpanTermExtractor to be aware of it.

Steps to Reproduce

POST script-score/_doc
{
  "text": "some text"
}

GET script-score/_search
{
  "query": {
    "script_score": {
      "script": {
        "source": "_score + 1"
      },
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "text": "some"
              }
            },
            {
              "exists": { "field": "text" }
            }
          ]
        }
      }
    }
  },
  "highlight": {
    "type": "plain",
    "fields": {
      "*": {}
    }
  }
}

Returns

{
  "error": {
    "root_cause": [
      {
        "type": "unsupported_operation_exception",
        "reason": "unsupported_operation_exception: null"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "script-score",
        "node": "TpI_NouPS1eIgeB4zNzGkg",
        "reason": {
          "type": "unsupported_operation_exception",
          "reason": "unsupported_operation_exception: null"
        }
      }
    ]
  },
  "status": 500
}

Logs (if relevant)

No response

@romseygeek romseygeek added >bug needs:triage Requires assignment of a team area label :Search/Highlighting How a query matched a document and removed needs:triage Requires assignment of a team area label labels Sep 20, 2023
@romseygeek romseygeek self-assigned this Sep 20, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Sep 20, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

romseygeek added a commit that referenced this issue Sep 22, 2023
ScriptScoreQuery is an elasticsearch query implementation that the plain
highlighter doesn't know anything about. To highlight it correctly, we need
to add some custom handling logic in our CustomQueryScorer.

Fixes #99700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Highlighting How a query matched a document Team:Search Meta label for search team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants