gpt4 book ai didi

elasticsearch - Elasticsearch 重新索引:WAITING完成

转载 作者:行者123 更新时间:2023-12-03 02:14:16 25 4
gpt4 key购买 nike

我正在尝试使用Nest C#重新索引2695140文档。我需要计算为所有文档重新编制索引所花费的时间,为此我已经写了日志。但是运行一分钟后,我的代码返回了无效响应(失败),但是由于我们触发了 Elasticsearch 的Reindex endint,因此文档已正确索引。
我希望我的代码应该等到重新索引操作完成后才能计算重新索引所花费的总时间。下面是我正在使用的代码

return await Client.ReindexOnServerAsync(selector => selector
.Source(src => src
.Index(_config.SomeIndex))
.Destination(dest => dest
.Index(newIndexName).OpType(OpType.Index))
.WaitForCompletion(true));
提前致谢。

最佳答案

I would want my code should wait until the reindex operation iscompleted


我不知道您使用的是哪种编程语言,但是本质上对于遵循“每个请求一个线程”模型的语言,等待重新索引操作并不明智。该操作所花费的时间将与要重新建立索引的文档数量成比例,并且它将阻塞线程(消耗资源),直到该操作完成为止。
相反,您应该:
  • 重新索引而无需等待完成,例如:

  • POST _reindex?wait_for_completion=false
    {
    "source":{
    "index":"book"
    },
    "dest":{
    "index":"book_new1"
    }
    }

    Response: will have task_id


  • 使用tasks API跟踪任务的完成。它还将包含状态(请求是否成功)以及操作所花费的时间。任务API的示例响应如下所示:

  • {
    "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
    }
    }

  • 您可以定期检查(使用cron / scheduler / etc),直到完成并采取必要的措施。
  • 关于elasticsearch - Elasticsearch 重新索引:WAITING完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63931824/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com