# How to filter between a particular id range

**URL:** <https://discuss.elastic.co/t/how-to-filter-between-a-particular-id-range/69875>\
**Category:** Elasticsearch\
**Created:** [December 23, 2016, 6:30am UTC](https://discuss.elastic.co/t/how-to-filter-between-a-particular-id-range/69875 "2016-12-23T06:30:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haozy](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@haozy](https://discuss.elastic.co/u/haozy)\
**Post date:** [December 23, 2016, 6:30am UTC](https://discuss.elastic.co/t/how-to-filter-between-a-particular-id-range/69875/1 "2016-12-23T06:30:17Z")

</div>

Before Elasticsearch 5, we were able to filter

```
   {
      "query": {
          "bool": {
             "filter": [
                 {
                    "range" : {
                        "_uid" : {
                            "gte" : "item#1600000",
                            "lte" :"item#1600100"
                        }
                    }
                 }
            ]
          }
       }
    }

```

However with Elasticsearch 5, it seems we are not able to do filter range and not able to perform range on uid.  
The closest direction has been to look at Ids query. However, it seems like there is no way to specify ids greater than or lesser than.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 23, 2016, 5:29pm UTC](https://discuss.elastic.co/t/how-to-filter-between-a-particular-id-range/69875/2 "2016-12-23T17:29:41Z")

</div>

That is not possible anymore indeed. One alternative would be to also add the id as a `keyword` field in your documents, and use that keyword field for the range query.

---

<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:** [January 20, 2017, 5:29pm UTC](https://discuss.elastic.co/t/how-to-filter-between-a-particular-id-range/69875/3 "2017-01-20T17:29:48Z")

</div>

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