我需要在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/