Shuklaswag
Shuklaswag

Reputation: 1023

How is the value of the _doc parameter determined in Elasticsearch? Is it ordered based on insertion?

I want to be able to control the order of the _doc parameter across all my documents. Is there a way to do this? Do I have to re-insert all the documents in my database?

Upvotes: 1

Views: 129

Answers (1)

femtoRgon
femtoRgon

Reputation: 33351

No, there is no way to do that.

Roughly speaking, yes, it will tend to sort on insertion order, but that is not a guarantee, and you should never rely on that sort staying the same. Like _score, _doc is not actually a field. It is lucene's internal document id. It can change without notice, and there is no way to explicitly set it's value. You should only sort on it when you don't care about the order.

If you want to have a value to sort your documents in a predictable fashion, you will need to index a field with that value.

Upvotes: 1

Related Questions