Sort by range field

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?

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

The search:

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

Error:

{
   "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.

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