# Elasticsearch Update query high level rest client java api

**URL:** https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060
**Category:** Elasticsearch
**Created:** [September 18, 2019, 5:21pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060 "2019-09-18T17:21:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)
#### Post date: [September 18, 2019, 5:21pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/1 "2019-09-18T17:21:38Z")

</div>

I am using elasticsearch high level rest client, i need to update the document in elasticsearch i have seen the document to update the single document but i need to update more than one document using condition how to do? which method i need to use?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 18, 2019, 6:49pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/2 "2019-09-18T18:49:40Z")

</div>

You are probably looking for [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update-by-query.html)

---

<div class="post-metadata">

### Author: ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)
#### Post date: [September 18, 2019, 6:55pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/3 "2019-09-18T18:55:08Z")

</div>

sir, I have go through document  
request.setQuery(new TermQueryBuilder("user", "kimchy"));  
this method is used to update all the document user to kimchy but i need to update same using condition like age \< 20 for this what this what i need to use  
sample sql query  
update index1 set name to kimchy where father\_name=ram

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 18, 2019, 7:09pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/4 "2019-09-18T19:09:32Z")

</div>

> [@Dv\_Thiyanesh](#):
>
> this method is used to update all the document user to kimchy

No.  
This is used to update all documents where `user` = `"kimchy"`.

---

<div class="post-metadata">

### Author: ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)
#### Post date: [September 18, 2019, 7:11pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/5 "2019-09-18T19:11:38Z")

</div>

yes sir, but i need to update specific document using condition for what can i do?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 18, 2019, 7:30pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/6 "2019-09-18T19:30:40Z")

</div>

You first need to understand how all this works before translating to Java code.  
Have a look at [https://www.elastic.co/guide/en/elasticsearch/reference/7.3/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/docs-update-by-query.html)

Once you found the right syntax, you can share the code with us and we can hopefully help you to transform to Java code but it should be easy.

---

<div class="post-metadata">

### Author: ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)
#### Post date: [September 18, 2019, 7:39pm UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/7 "2019-09-18T19:39:34Z")

</div>

ok sir, there is no one like i would asked?  
see i need to update salaries of employee whose ages are greater than 25 for this there is no dsl query types to update? here showing is only full documentation update what i need to do?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 25, 2019, 11:43am UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/8 "2019-09-25T11:43:13Z")

</div>

It's probably something like:

```auto
POST twitter/_update_by_query
{
  "script": {
    "source": "ctx._source.salary+=100",
    "lang": "painless"
  },
  "query": {
    "range": {
      "age": {
        "gte": 25
      }
    }
  }
}

```

---

<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: [October 23, 2019, 11:45am UTC](https://discuss.elastic.co/t/elasticsearch-update-query-high-level-rest-client-java-api/200060/9 "2019-10-23T11:45:04Z")

</div>

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