Elasticsearch Update query high level rest client java api

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?

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

1 Like

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

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

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

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

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.

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?

It's probably something like:

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

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