L
L
loly2016-04-16 19:46:52
Database
loly, 2016-04-16 19:46:52

How to change the "primary key" in Elasticsearch (i.e. use a different field instead of _id)?

There is a need to replace existing elements with new ones, about 10 times per second. Naturally, you can first search and delete existing ones, and then add new ones, but this seems far from the best solution (because I am a student and there is no particularly powerful hardware).
"Primary key" or just a unique field is of type string ("string") and represents some unique sequence (something like a hash) that belongs to a strictly defined object.
Yes, I found this

"_id" : {
  "path" : "id"
}

but it has been depricated since version 1.5, I have 2.2.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MintTea, 2016-04-18
@MintTea

I couldn't understand why replacing the _id field with something else would solve your problem.
First, _id can be defined by the client. Read more: tyts .
If you don't like the id generated by elastic, just pass your own when creating the document.
Firstly, ES supports grouping operations in a single request if performance is a problem:
https://www.elastic.co/guide/en/elasticsearch/refe...
An example of creating a document with a predefined id (in this case 12345) :

curl -XPUT 0.0.0.0:9200/index_name/type_name/12345/ -d '{
    "hey": "there"
}'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question