gpt4 book ai didi

elasticsearch - 如何响应批量操作检测故障?

转载 作者:行者123 更新时间:2023-12-03 01:26:33 25 4
gpt4 key购买 nike

我正在使用elasticsearch npm库。

我使用批量API为文档建立索引:

const response = await this.elasticSearchClient.bulk({
body: bulkRows,
});

有用。

但是,如果ElasticSearch在某些索引编制上失败了,我如何从响应中检测到那些失败呢?

我在文档( https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)中找到了示例响应,但是我仍然不知道如何检测故障:

最佳答案

您可以通过检查从批量调用中获得的响应来做到这一点:

  const { body: bulkResponse } = await this.elasticSearchClient.bulk({ body: bulkRows })

if (bulkResponse.errors) {
const erroredDocuments = []

bulkResponse.items.forEach((action, i) => {
const operation = Object.keys(action)[0]
if (action[operation].error) {
erroredDocuments.push({
// If the status is 429 it means that you can retry the document,
// otherwise it's very likely a mapping error, and you should
// fix the document before to try it again.

status: action[operation].status,
error: action[operation].error,
operation: body[i * 2],
document: body[i * 2 + 1]
})
}
})

console.log(erroredDocuments)
}

关于elasticsearch - 如何响应批量操作检测故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58027578/

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