从ES
2.3开始,按查询更新功能可用作REST端点,
_update_by_query但不适用于Java客户端。为了从Java客户端代码中调用此端点,您需要
reindex在pom.xml中包含该模块,如下所示
<dependency> <groupId>org.elasticsearch.module</groupId> <artifactId>reindex</artifactId> <version>2.3.2</version></dependency>
然后,在构建客户端时需要包括以下模块:
clientBuilder.addPlugin(ReindexPlugin.class);
最后,您可以这样称呼它:
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();更新
如果您需要指定更新应关注的类型,则可以执行以下操作:
ubqrb.source("twitter").source().setTypes("type1");BulkIndexByScrollResponse r = ubqrb.script(script) .filter(termQuery("user", "kimchy")) .get();


