# How to Update Value inside Native Script Plugin

**URL:** https://discuss.elastic.co/t/how-to-update-value-inside-native-script-plugin/72132
**Category:** Elasticsearch
**Created:** [January 19, 2017, 8:22am UTC](https://discuss.elastic.co/t/how-to-update-value-inside-native-script-plugin/72132 "2017-01-19T08:22:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deerawan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deerawan/32/14676_2.png) [@deerawan](https://discuss.elastic.co/u/deerawan)
#### Post date: [January 19, 2017, 8:22am UTC](https://discuss.elastic.co/t/how-to-update-value-inside-native-script-plugin/72132/1 "2017-01-19T08:22:28Z")

</div>

Hello guys,

I saw this snippet where update\_by\_query can update source directly

```auto
POST twitter/_update_by_query
{
  "script": {
    "inline": "ctx._source.likes++",
    "lang": "painless"
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}

```

instead of using painless, I wrote a native script plugin in Java because of my complex business logic. Then **I need to update multiple fields value including the ones in nested object.**

```java
public Object run() {
     // change field value of "subtotal"
     // change field value of "total"   

   return true;
}

```

I was trying with `source().put("subtotal", 3000)` but I kept getting `NullPointerException`

---

<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 16, 2017, 8:22am UTC](https://discuss.elastic.co/t/how-to-update-value-inside-native-script-plugin/72132/2 "2017-02-16T08:22:46Z")

</div>

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