我正在尝试添加文档,根据 Elasticsearch 文档,我们可以添加文档,即使我们不提供id... See Here
我正在尝试添加文档,即使它没有任何 ID。在 Elasticsearch 中,我该怎么做? 我当前的代码如下所示
var params = _.defaults({}, {
index: index,
type: type, //'customer'
id: data.id || null,
body: data
})
debug(params)
return this.client.create(params);
上面的代码给出了这个错误
{ "error": "Unable to build a path with those params. Supply at least index, type, id" }
任何提示都会有所帮助,谢谢
最佳答案
使用 create
调用您必须提供一个 ID。
如果您不确定您的 data
中是否会出现 ID,那么您可以使用 client.index()
function反而。使用该函数,如果没有提供 ID,ES 将自动生成一个 ID。
关于node.js - elastic js v5.0文档中没有id时如何自动生成id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40611065/