简体   繁体   English

通过查询更新Elasticsearch Java客户端并等待完成

[英]Elasticsearch java client update by query with wait for completion

Elasticsearch version 5.6 Elasticsearch 5.6版

I'm using the elasticsearch native transport client and the UpdateByQueryRequestBuilder to perform an update by query . 我正在使用UpdateByQueryRequestBuilder本机传输客户端和UpdateByQueryRequestBuilder 通过query执行更新

I'd like to perform this asynchronously and track progress with the tasks api. 我想异步执行此操作并跟踪任务api的进度。 The docs show that the parameter wait_for_completion=false is exactly what I want by I can't see support for the on the java client. 文档显示,参数wait_for_completion = false正是我想要的,因为我在Java客户端上看不到对的支持。 Is there a way to set this and get the task id back ? 有没有一种方法可以设置此项并获取任务ID?

Using the native transport client for retrieving the task api response you have to perform the request like this: 使用本机传输客户端来检索任务api响应,您必须执行以下请求:

UpdateByQueryRequestBuilder u = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
BulkIndexByScrollResponse r = u.source("source").filter(matchQuery("field", "value")).get();

The response has two lists of failures and status member you can use get counts. 响应有两个失败列表和状态成员,您可以使用获取计数。 The status is exactly the same status as you can get from the task management API. 该状态与您从任务管理API中获得的状态完全相同。

Only in case you have dependencies missing, try importing this maven dependency: 仅在缺少依赖项的情况下,请尝试导入以下Maven依赖项:

    <dependency>
    <groupId>org.elasticsearch.module</groupId>
    <artifactId>reindex</artifactId>
    <version>x.x.x</version>
    </dependency>

And adding call this in the client setup: 并在客户端设置中添加此命令:

clientBuilder.addPlugin(ReindexPlugin.class);

You can find additional information here. 您可以在此处找到其他信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM