elastic js v5.0文档中没有id时如何自动生成id
How to autogenerate id if there is no id in document with elasticjs v5.0
我正在尝试添加文档,根据elasticsearch文档,我们可以添加文档,即使我们不提供id... See Here
我正在尝试添加文档,即使它没有任何 ID。在弹性搜索中,我该怎么做?
我当前的代码如下所示
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。使用该函数,如果提供 none,ES 将自动生成一个 ID。
我正在尝试添加文档,根据elasticsearch文档,我们可以添加文档,即使我们不提供id... See Here
我正在尝试添加文档,即使它没有任何 ID。在弹性搜索中,我该怎么做? 我当前的代码如下所示
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。使用该函数,如果提供 none,ES 将自动生成一个 ID。