Is it possible to use range aggregations in ElasticSearch with alphabetical ranges?

Viewed 50

In ElasticSearch range queries can be used with text ("from" : "Bread").

Is it possible to do the same with "range aggregations"?

I am trying :

"aggs" : "slice" {
 "range" : { "ranges" : [{"from" : "Bread"}],"field" : "content.keyword"}
}

and I am getting :

   "root_cause" : [
      {
         "type" : "number_format_exception",
         "reason" : "For input string: \"Bread\""
      }
   ],
   "reason" : "all shards failed",
   "phase" : "query",
   "caused_by" : {
      "reason" : "For input string: \"Bread\"",
      "type" : "number_format_exception",
      "caused_by" : {
         "reason" : "For input string: \"Bread\"",
         "type" : "number_format_exception"
      }
   },
   "type" : "search_phase_execution_exception"

If so, would there be a workaround?

1 Answers

You can apply that range query to a terms agg if that's what you're after:

{
  "size": 0,
  "aggs": {
    "filtered_content_terms": {
      "filter": {
        "range": {
          "content.keyword": {
            "gte": "Bread"
          }
        }
      },
      "aggs": {
        "content_terms": {
          "terms": {
            "field": "content.keyword",
            "size": 10
          }
        }
      }
    }
  }
}
Related