RestHighLevelClient脚本更新设置wait_for_completion属性

UpdateByQueryRequest参数没有直接设置wait_for_completion的属性
通过使用客户端封装的submitUpdateByQueryTask方法调用:


TaskSubmissionResponse taskSubmissionResponse = writeHighLevelClient.submitUpdateByQueryTask(request, RequestOptions.DEFAULT);

public final TaskSubmissionResponse submitUpdateByQueryTask(UpdateByQueryRequest updateByQueryRequest,
                                                                RequestOptions options) throws IOException {
        return performRequestAndParseEntity(
            updateByQueryRequest, RequestConverters::submitUpdateByQuery, options, TaskSubmissionResponse::fromXContent, emptySet()
        );
    }
static Request submitUpdateByQuery(UpdateByQueryRequest updateByQueryRequest) throws IOException {
        return prepareUpdateByQueryRequest(updateByQueryRequest, false);
    }

private static Request prepareReindexRequest(ReindexRequest reindexRequest, boolean waitForCompletion) throws IOException {
        String endpoint = new EndpointBuilder().addPathPart("_reindex").build();
        Request request = new Request(HttpPost.METHOD_NAME, endpoint);
        Params params = new Params()
            .withWaitForCompletion(waitForCompletion)
            .withRefresh(reindexRequest.isRefresh())
            .withTimeout(reindexRequest.getTimeout())
            .withWaitForActiveShards(reindexRequest.getWaitForActiveShards())
            .withRequestsPerSecond(reindexRequest.getRequestsPerSecond())
            .withSlices(reindexRequest.getSlices());

        if (reindexRequest.getScrollTime() != null) {
            params.putParam("scroll", reindexRequest.getScrollTime());
        }
        request.addParameters(params.asMap());
        request.setEntity(createEntity(reindexRequest, REQUEST_BODY_CONTENT_TYPE));
        return request;
    }



posted @ 2023-12-29 10:18  748573200000  阅读(149)  评论(0编辑  收藏  举报