Elasticsearch: NPE ES 7.4 Script score

Created on 15 Oct 2019  路  2Comments  路  Source: elastic/elasticsearch

NPE when using script scores query across multiple indices.

When a range clause is written on a field that exists in just one index, the other indices throw NPE.

org.elasticsearch.transport.RemoteTransportException: [MSEAIT1034064][127.0.0.1:9300][indices:data/read/search[phase/dfs]]

Caused by: java.lang.NullPointerException

at org.elasticsearch.index.query.functionscore.ScriptScoreQueryBuilder.doRewrite(ScriptScoreQueryBuilder.java:176) ~[elasticsearch-7.4.0.jar:7.4.0]
at org.elasticsearch.index.query.AbstractQueryBuilder.rewrite(AbstractQueryBuilder.java:265) ~[elasticsearch-7.4.0.jar:7.4.0]
at org.elasticsearch.search.builder.SearchSourceBuilder.rewrite(SearchSourceBuilder.java:962) ~[elasticsearch-7.4.0.jar:7.4.0]
at org.elasticsearch.search.builder.SearchSourceBuilder.rewrite(SearchSourceBuilder.java:82) ~[elasticsearch-7.4.0.jar:7.4.0]
at org.elasticsearch.index.query.Rewriteable.rewrite(Rewriteable.java:68) ~[elasticsearch-7.4.0.jar:7.4.0]

If the script_score clause is removed, the query runs fine.

POST ind1, ind2, ind3/_search?search_type=dfs_query_then_fetch

{
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "should": [
            {
              "multi_match": {
                "query": "HR policies",
                "fields": [
                  "title",
                  "body"
                ]
              }
            },
            {
              "range": {
                "ind1+valid_to": {
                  "from": "now",
                  "to": null,
                  "include_lower": true,
                  "include_upper": true,
                  "boost": 1
                }
              }
            }
          ]
        }
      },
      "script": {
        "source": "return 1;"
      }
    }
  }
}
:SearcSearch >bug

Most helpful comment

Looks like we're trying to unbox a null value into a float when the query is rewritten. It should work if you add a "minScore": 0" in the script_sore like this:
{ "query": { "script_score": { "min_score": 0, ....
... but this is definitely a bug. @mayya-sharipova can you take a look ?

All 2 comments

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

Looks like we're trying to unbox a null value into a float when the query is rewritten. It should work if you add a "minScore": 0" in the script_sore like this:
{ "query": { "script_score": { "min_score": 0, ....
... but this is definitely a bug. @mayya-sharipova can you take a look ?

Was this page helpful?
0 / 5 - 0 ratings