Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set _id in elasticsearch 2.0

Since the configuration of path on the _id field of a specific mapping is deprecated (as noted in the documentation here),

How can I set the _id field for a specific document in elasticsearch 2.0 ?

(In my specific use-case, I want to index all documents with my own id. I know they're all unique)

like image 635
gillyb Avatar asked Sep 01 '15 14:09

gillyb


1 Answers

_id being deprecated simply means that you have to specify the id explicitly and ES won't offer you to parse your document a first time just to retrieve the field you've specified as the id field.

So all the current ways of indexing your documents are still valid as long as you specify the id explicitly:

curl -XPUT localhost:9200/index/type/your_id -d '{"field1": "value1"}'
                                        ^
                                        |
                                 your id goes here

or in a bulk query

curl -XPOST localhost:9200/_bulk -d '
{"index": {"_index": "index", "_type": "type", "_id": "your_id"}}
{"field1": "value1"}                                     ^
'                                                        |
                                                 your id goes here
like image 190
Val Avatar answered Oct 22 '22 11:10

Val