简体   繁体   English

避免在 Elasticsearch 中超时,在 Java 中重新索引

[英]Avoid timeout in Elasticsearch re-indexing in Java

Below code returned a timeout in client (Elasticsearch Client) when number of records are higher.当记录数较高时,以下代码在客户端(Elasticsearch 客户端)中返回超时。

CompletableFuture<BulkByScrollResponse> future = new CompletableFuture<>();
client.reindexAsync(request, RequestOptions.DEFAULT, new ActionListener<BulkByScrollResponse>() {
@Override
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
    future.complete(bulkByScrollResponse);
}

@Override
public void onFailure(Exception e) {
    future.completeExceptionally(e);
}
});
BulkByScrollResponse response = future.get(10, TimeUnit.MINUTES); // client timeout occured before this timeout

Below is the client config.下面是客户端配置。

connectTimeout: 60000
socketTimeout: 600000
maxRetryTimeoutMillis: 600000

Is there a way to wait indefinitely until the re-indexing complete?有没有办法无限期地等待重新索引完成?

submit the reindex request as a task:将重建索引请求作为任务提交:

TaskSubmissionResponse task = esClient.submitReindexTask(reindex, RequestOptions.DEFAULT);

acquire the task id:获取任务id:

TaskId taskId = new TaskId(task.getTask());

then check the task status periodically:然后定期检查任务状态:

        GetTaskRequest taskQuery = new GetTaskRequest(taskId.getNodeId(), taskId.getId());
        GetTaskResponse taskStatus;
        do {
            Thread.sleep(TimeUnit.MINUTES.toMillis(1));
            taskStatus = esClient.tasks()
                    .get(taskQuery, RequestOptions.DEFAULT)
                    .orElseThrow(() -> new IllegalStateException("Reindex task not found. id=" + taskId));
        } while (!taskStatus.isCompleted());

Elasticsearch java api doc about task handling just sucks. Elasticsearch java api 关于任务处理的文档很烂。

Ref 参考

I don't think its a better choice to wait indefinitely to complete the re-indexing process and give very high value for timeout as this is not a proper fix and will cause more harm than good.我认为无限期地等待完成重新索引过程并为超时提供非常高的值并不是一个更好的选择,因为这不是一个正确的解决方法,而且弊大于利。

Instead you should examine the response, add more debugging logging to find the root-cause and address them.相反,您应该检查响应,添加更多调试日志以找到根本原因并解决它们。 Also please have a look at my tips to improve re-indexing speed , which should fix some of your underlying issues.另请查看我的提示以提高重新索引速度,这应该可以解决您的一些潜在问题。

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

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