Mou*_*aik 5 elasticsearch elasticsearch-rest-client
我正在尝试使用 Nest C# 重新索引 2695140 个文档。我需要计算重新索引所有文档(我已为其编写日志)所需的时间。但运行 1 分钟后,我的代码返回无效响应(失败),但文档已正确索引,因为我们触发了弹性搜索的重新索引 Endint。
我希望我的代码应该等到重新索引操作完成,以便我可以计算重新索引所需的总时间。下面是我正在使用的代码
return await Client.ReindexOnServerAsync(selector => selector
.Source(src => src
.Index(_config.SomeIndex))
.Destination(dest => dest
.Index(newIndexName).OpType(OpType.Index))
.WaitForCompletion(true));
Run Code Online (Sandbox Code Playgroud)
提前致谢。
我希望我的代码应该等到重新索引操作完成
我不知道您使用的是哪种编程语言,但本质上对于遵循“每个请求一个线程”模型的语言,等待重新索引操作是不明智的。该操作所花费的时间将与要重新索引的文档数量成正比,并且它会阻塞线程(消耗资源),直到操作完成。
相反,你应该:
Run Code Online (Sandbox Code Playgroud)POST _reindex?wait_for_completion=false { "source":{ "index":"book" }, "dest":{ "index":"book_new1" } }
响应:将有task_id
Run Code Online (Sandbox Code Playgroud){ "completed" : true, "task" : { "node" : "jF8smI1eR1mwwNxl8_7z2A", "id" : 2427911 }, "description" : "reindex from [book] to [book_new1][_doc]", "start_time_in_millis" : 1600335207787, "running_time_in_nanos" : 640430472, "cancellable" : true, "headers" : { } }, "response" : { "took" : 634, // <====== Time taken by operation "timed_out" : false, "total" : 3, "updated" : 0, "created" : 3, "deleted" : 0, "batches" : 1, "version_conflicts" : 0, "noops" : 0 } }
归档时间: |
|
查看次数: |
9028 次 |
最近记录: |