user3631116
user3631116

Reputation:

How to specify explicit document id in elasticsearch while performing a bulk index operation?

I have to perform a bulk index operation in elasticsearch. The data looks like

[{'code': 12, 'name': 'ABC', 'designation': 'ceo'}, 
 {'code': 13, 'name': 'AIB', 'designation': 'cfo'}, 
 {'code': 14, 'name': 'AXB', 'designation': 'cto'}]

While indexing i want to explicitly provide code as the id. It is simple when performing single indexing operation. I am not sure as to how can it be done in bulk index operation.

Upvotes: 0

Views: 410

Answers (1)

Vineeth Mohan
Vineeth Mohan

Reputation: 19263

For indexing the format is different for bulk. There need to be 2 lines per index request. First one for meta data like indexname , type name and ID and second one , actual data -

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }

You can specify the id in the first field. You can read more on this here.

Upvotes: 1

Related Questions