是否可以在ElasticSearch中使用字母范围使用范围聚合?

时间:2020-06-06 16:45:07

标签: elasticsearch range aggregation

在ElasticSearch范围中,查询可以与文本(“ from”:“ Bread”)一起使用。

是否可以对“范围聚合”做同样的事情?

我正在尝试:

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

我得到了:

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

如果是这样,会有解决方法吗?

1 个答案:

答案 0 :(得分:0)

如果您要这样做,可以将range查询应用于terms agg:

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