如何通过Java API将scroll_size设置为_update_by_query请求

时间:2019-02-21 10:37:21

标签: elasticsearch

我找到了有关“通过查询更新”请求的文档

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-update-by-query.html

问题是:如何在“ _update_by_query”查询中添加URL参数:

我添加的示例:

pre_production / _update_by_query?slices = 200&scroll_size = 1000

如何添加这两个参数(切片,scroll_size)以使用JAVA Api?

1 个答案:

答案 0 :(得分:1)

You can use the UpdateByQueryRequestBuilder instance in order to modify the number of slices:

UpdateByQueryRequestBuilder updateByQuery =
  UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
updateByQuery.source("source_index")
    .source()
    .setSlices(200);                 <--- set the number of slices

However, to change the scroll_size parameter you need to access the underlying UpdateByQueryRequest instance as the builder doesn't have any setBatchSize() method. You can do it like this:

((UpdateByQueryRequest) updateByQuery.getRequest()).setBatchSize(1000);