_id range query [v6.1.x]

Hi,

I would like to query by range for the "_id" property. I tried adding the "_id" on index time but as for v6.1.x is already added is not needed. I tried to query using a range but an exception is thrown with reason: "Field [_id] of type [_id] does not support range queries". Trying to update the mapping I get: "Field [_id] is defined twice in [doc]".

How can I modify the mapping or anything else to achieve this behaviour that seems was possible in <v6.0?

Many thanks :slight_smile:

Yes, in 6.x you can NOT do range queries on _id field. But, you can do term or terms query on this field.

In 5.x, _id field was not indexed, its value was derived automatically from the _uid field.
In 6.x, _id field is indexed, and it is encoded in a special binary encoding, which makes range queries on this field not trivial.

2 Likes

Many thanks for answering @mayya. I ended using the official pagination (size, from) to get it working but hopefully at some point in future there is a workaround to this as if we want a cursor approach for pagination there is not an alternative right now to achieve it with ES.

You can implement a cursor approach for pagination using search_after and sorting on _id field: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.