Muhammad Faizan Muhammad Faizan - 1 year ago 304
Node.js Question

How to autogenerate id if there is no id in document with elasticjs v5.0

I am trying to add documents, according to elastic search documents, we can add document, even if we dont provide id... See Here

I am trying to add a document even if it doesnt have any ID. in elastic search, how can i do that?
My current code looks like this

var params = _.defaults({}, {
index: index,
type: type, //'customer'
id: || null,
body: data
return this.client.create(params);

The above code gives this error

"error": "Unable to build a path with those params. Supply at least index, type, id"

Any hint would help, thanks

Val Val
Answer Source

With the create call you MUST provide an id.

If you are not sure if an ID will be present in your data , then you can use the client.index() function instead. using that function, ES will auto-generate an ID if none is provided.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download