Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: data.id || null,
    body: data
})
debug(params)
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

like image 245
Muhammad Faizan Avatar asked Dec 18 '22 12:12

Muhammad Faizan


1 Answers

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.

like image 126
Val Avatar answered May 16 '23 05:05

Val