# Can not access to params.\_source in script\_score

**URL:** <https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851>\
**Category:** Elasticsearch\
**Created:** [October 24, 2018, 4:44pm UTC](https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851 "2018-10-24T16:44:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wgkoro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wgkoro/32/36902_2.png) [@wgkoro](https://discuss.elastic.co/u/wgkoro)\
**Post date:** [October 24, 2018, 4:44pm UTC](https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851/1 "2018-10-24T16:44:57Z")

</div>

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.

```auto
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

```auto
{
  "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 ...

---

<div class="post-metadata">

**Author:** ![wgkoro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wgkoro/32/36902_2.png) [@wgkoro](https://discuss.elastic.co/u/wgkoro)\
**Post date:** [October 24, 2018, 4:55pm UTC](https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851/2 "2018-10-24T16:55:34Z")

</div>

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"?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [October 24, 2018, 6:36pm UTC](https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851/3 "2018-10-24T18:36:54Z")

</div>

In this particular case, the issue is an unintentional side effect of [refactoring](https://github.com/elastic/elasticsearch/pull/30816). 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?

---

<div class="post-metadata">

**Author:** ![wgkoro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wgkoro/32/36902_2.png) [@wgkoro](https://discuss.elastic.co/u/wgkoro)\
**Post date:** [October 25, 2018, 1:37am UTC](https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851/4 "2018-10-25T01:37:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 22, 2018, 1:37am UTC](https://discuss.elastic.co/t/can-not-access-to-params-source-in-script-score/153851/5 "2018-11-22T01:37:02Z")

</div>

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