Can not access to params._source in script_score

Hi. newbie here.
I'm trying to write script_score with params._source, but it returns null pointer exception.
(I want to access nested data)
Query is like this.

GET /users/_search
{
  "query": {
    "function_score": {
        "query" : {
          "match_all": {}
        },
        "score_mode" : "sum",
        "boost_mode" : "sum",
        "script_score": {
          "script": {
            "lang": "painless",
            "source": "if (params._source['categories'][0]['category_id'] == 3) { 10 } else { -50 }"
          }
        }
      }
    }
  }

It returns

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "if (params._source['categories'][0]['category_id'] == 3) { ",
          "          ^---- HERE"
        ],
        "script": "if (params._source['categories'][0]['category_id'] == 3) { 10 } else { -50 }",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "users",
        "node": "xxxxxxxxxxxxxxxxx(filtered)",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "if (params._source['categories'][0]['category_id'] == 3) { ",
            "          ^---- HERE"
          ],
          "script": "if (params._source['categories'][0]['category_id'] == 3) { 10 } else { -50 }",
          "lang": "painless",
          "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
          }
        }
      }
    ]
  },
  "status": 500
}

How can I access params['_source'] in script_score?
※ Elasticsearch version ... 6.4.2

params.containsKey('_source') returns false, params.isEmpty() returns true ...

In local machine,
I tried with version 6.3.2 => No errors
version 6.4.2 => Error

Does 6.4.x changed something around "params"?

In this particular case, the issue is an unintentional side effect of refactoring. However, it does fall in line with long suggested guidance, which is accessing _source in scoring scripts is slow and should not be done.

Do you have doc values disabled for categories and category_id?

Thank you for reply.

the issue is an unintentional side effect of refactoring

Oh I see..

Do you have doc values disabled for categories and category_id?

Now not.I have to find alternative.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.