# How to update a document using script? (es\_version=8.4.3, javaApi)

**URL:** <https://discuss.elastic.co/t/how-to-update-a-document-using-script-es-version-8-4-3-javaapi/320246>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 1, 2022, 12:58pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-script-es-version-8-4-3-javaapi/320246 "2022-12-01T12:58:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![infinite-war](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/infinite-war/32/114093_2.png) [@infinite-war](https://discuss.elastic.co/u/infinite-war)\
**Post date:** [December 1, 2022, 12:58pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-script-es-version-8-4-3-javaapi/320246/1 "2022-12-01T12:58:44Z")

</div>

# config

elasticsearch 8.4.3 (javaApi)  
JDK 17

# created index

```auto
PUT testdb
{
  "mappings": {
    "properties": {
      "name":{
        "type":"text"
      },
      "desc":{
        "type":"text"
      },
      "score":{
        "type": "integer"
      }
    }
  }
}

PUT testdb/_doc/1
{
  "name": "bookA",
  "desc": "a desc",
  "score":36305
}

PUT testdb/_doc/2
{
  "name": "bookB",
  "desc":"a desc",
  "score": 1000
}

```

 ![Snipaste_2022-12-01_20-51-45](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5eeb047e99b7ae0a2da3cc924f2b8c5300601ea8.png)

# question

Now I want to add 125 points to bookB's score , the request statement should be like this

```auto
POST testdb/_update/2
{
  "script":"ctx._source.score+=125"
}

```

here I use a script to make an add operation for bookB's score , and actually it works.

 ![Snipaste_2022-12-01_20-52-38](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f61590c05f2e5fb2eb622e934b30d4123cefc21c.png)

However, I want to create this request statement by javaApi ,how can I do this?(I haven't found a solution in elasticsearch's docs yet)

---

<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:** [December 29, 2022, 12:58pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-script-es-version-8-4-3-javaapi/320246/2 "2022-12-29T12:58:57Z")

</div>

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