# \_id range query \[v6.1.x\]

**URL:** <https://discuss.elastic.co/t/id-range-query-v6-1-x/118046>\
**Category:** Elasticsearch\
**Created:** [February 1, 2018, 3:13pm UTC](https://discuss.elastic.co/t/id-range-query-v6-1-x/118046 "2018-02-01T15:13:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andfk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andfk/32/27258_2.png) [@andfk](https://discuss.elastic.co/u/andfk)\
**Post date:** [February 1, 2018, 3:13pm UTC](https://discuss.elastic.co/t/id-range-query-v6-1-x/118046/1 "2018-02-01T15:13:00Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [February 15, 2018, 12:39am UTC](https://discuss.elastic.co/t/id-range-query-v6-1-x/118046/2 "2018-02-15T00:39:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andfk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andfk/32/27258_2.png) [@andfk](https://discuss.elastic.co/u/andfk)\
**Post date:** [February 15, 2018, 9:15am UTC](https://discuss.elastic.co/t/id-range-query-v6-1-x/118046/3 "2018-02-15T09:15:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [February 15, 2018, 3:09pm UTC](https://discuss.elastic.co/t/id-range-query-v6-1-x/118046/4 "2018-02-15T15:09:24Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 15, 2018, 3:09pm UTC](https://discuss.elastic.co/t/id-range-query-v6-1-x/118046/5 "2018-03-15T15:09:30Z")

</div>

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