I’m currently using Elasticsearch V2.3.1. I want to use the following Elasticsearch query in Java.
POST /twitter/_update_by_query
{
\"script\": {
\"in
As of ES 2.3, the update by query feature is available as the REST endpoint _update_by_query but nor for Java clients. In order to call this endpoint from your Java client code, you need to include the reindex module in your pom.xml, like this
org.elasticsearch.module
reindex
2.3.2
Then you need to include this module when building your client:
clientBuilder.addPlugin(ReindexPlugin.class);
Finally you can call it like this:
UpdateByQueryRequestBuilder ubqrb = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
Script script = new Script("ctx._source.List = [\"Item 1\",\"Item 2\"]");
BulkIndexByScrollResponse r = ubqrb.source("twitter")
.script(script)
.filter(termQuery("user", "kimchy"))
.get();
UPDATE
If you need to specify the type(s) the update should focus on, you can do so:
ubqrb.source("twitter").source().setTypes("type1");
BulkIndexByScrollResponse r = ubqrb.script(script)
.filter(termQuery("user", "kimchy"))
.get();