# Sort by range field

**URL:** <https://discuss.elastic.co/t/sort-by-range-field/147834>\
**Category:** Elasticsearch\
**Created:** [September 8, 2018, 10:51pm UTC](https://discuss.elastic.co/t/sort-by-range-field/147834 "2018-09-08T22:51:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [September 8, 2018, 10:51pm UTC](https://discuss.elastic.co/t/sort-by-range-field/147834/1 "2018-09-08T22:51:08Z")

</div>

I cannot find a canonical answer anywhere to this question. I've seen it asked on this forum with no replies.

Using ES 5.6.x, Is it possible make a range field (in my case, a date\_range field) sortable?

```auto
{
   "activity-related-20180906-114842": {
      "mappings": {
         "doc": {
            "properties": {
               "date_range": {
                  "type": "date_range"
               }
            }
         }
      }
   }
}

```

The search:

```auto
POST /activity-related/_search
{
   "query": {
      "bool": {
         "must": [
            {
               "range": {
                  "date_range": {
                     "gte": "2018-09-10",
                     "lte": "2018-10-15",
                     "relation": "within"
                  }
               }
            }
         ]
      }
   },
   "sort": ["date_range"]
}

```

Error:

```auto
{
   "error": {
      "root_cause": [
         {
            "type": "illegal_argument_exception",
            "reason": "Fielddata is not supported on field [date_range] of type [date_range]"
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": "activity-related-20180906-114842",
            "node": "wlHACLYyQt-VAkm7huOVnw",
            "reason": {
               "type": "illegal_argument_exception",
               "reason": "Fielddata is not supported on field [date_range] of type [date_range]"
            }
         }
      ]
   },
   "status": 400
}

```

If this is mentioned in the docs somewhere, I'd appreciate someone pointing it out - otherwise an answer.

---

<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:** [October 6, 2018, 10:51pm UTC](https://discuss.elastic.co/t/sort-by-range-field/147834/2 "2018-10-06T22:51:11Z")

</div>

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