gpt4 book ai didi

node.js:使用用户定义的id在elasticsearch中进行数据索引

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:42 25 4
gpt4 key购买 nike

我需要在elasticsearch中索引多个json,索引id应该由用户给出,而不是由elasticserach自动创建。

请告诉我如何阻止elasticsearch创建自动索引id以及如何使用我想要的id进行数据索引。

下面是用于索引数据的node.js代码部分:

elasticSearchClient.index('index_name', 'type', json)
.on('data', function(data) {
console.log("************ "+data+" ****************")
})
.exec()

任何帮助将不胜感激!

问候

最佳答案

只需在 json 文档中包含 id 字段即可。它将自动从文档中提取并放入 url 中。事实上core.js脚本包含以下逻辑:

if (document.id) {
path += "/" + document.id
method = 'PUT'
delete document.id
}

关于node.js:使用用户定义的id在elasticsearch中进行数据索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12704107/

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