# Trying to pass params to elasticsearch getting null\_pointer\_exception

**URL:** https://discuss.elastic.co/t/trying-to-pass-params-to-elasticsearch-getting-null-pointer-exception/163230
**Category:** Elasticsearch
**Tags:** painless
**Created:** [January 7, 2019, 3:24pm UTC](https://discuss.elastic.co/t/trying-to-pass-params-to-elasticsearch-getting-null-pointer-exception/163230 "2019-01-07T15:24:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![qballer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qballer/32/39513_2.png) [@qballer](https://discuss.elastic.co/u/qballer)
#### Post date: [January 7, 2019, 3:24pm UTC](https://discuss.elastic.co/t/trying-to-pass-params-to-elasticsearch-getting-null-pointer-exception/163230/1 "2019-01-07T15:24:24Z")

</div>

I'm trying to send to Elasticsearch the following query. Here is the most minimal update by query which gives me the exception. Lets name it Query1:

```auto
{
  "id": "someID",
  "script": {
    "lang": "painless",
    "source": " if (ctx._source.containsKey('value')) { ctx._source.value = ctx._source.value + params.value; }"
  },
  "params": {
    "value": 1
  },
  "upsert": {
    "value": 1
  }
}

```

Been trying to hunt down this issue for a while now. In our case the parameter value is indexed as an `integer`. The query it's self is being sent as part of a bulk API. Which looks like as a following:

```auto
{update: {_id:"someID", _index:"someIndex", _type:"someType"}}
(Query1)

```

when trying to run the script it will have a run time exception:  
null\_point\_exception

```auto
params.value 
      ^--- here

```

I've seen [related](https://stackoverflow.com/questions/53336532/nullpointerexceptions-when-accessing-elasticsearch-painless-scripted-metric-aggr?noredirect=1#comment94976717_53336532) issues to this one but non which contains solutions. In stack overflow and other sites.

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [January 7, 2019, 5:51pm UTC](https://discuss.elastic.co/t/trying-to-pass-params-to-elasticsearch-getting-null-pointer-exception/163230/2 "2019-01-07T17:51:28Z")

</div>

The `params` should be inside the `script` block. Something like this should work:

```auto
  "script": {
    "lang": "painless",
    "source": " if (ctx._source.containsKey('value')) { ctx._source.value = ctx._source.value + params.value; }"
    "params": {
        "value": 1
    }
  }

```

---

<div class="post-metadata">

### Author: ![qballer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qballer/32/39513_2.png) [@qballer](https://discuss.elastic.co/u/qballer)
#### Post date: [January 7, 2019, 6:42pm UTC](https://discuss.elastic.co/t/trying-to-pass-params-to-elasticsearch-getting-null-pointer-exception/163230/3 "2019-01-07T18:42:44Z")

</div>

I feel really silly. wow thanks.

---

<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: [February 4, 2019, 6:42pm UTC](https://discuss.elastic.co/t/trying-to-pass-params-to-elasticsearch-getting-null-pointer-exception/163230/4 "2019-02-04T18:42:45Z")

</div>

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