在ElasticSearch中将术语从聚合分组到存储桶中

时间:2018-10-18 09:55:06

标签: elasticsearch group-by bucket

我正在尝试在Elastic Search中将一些分组的数据分组到超集存储桶中,但找不到。

我的查询如下:

GET /items/_search
{
  "query" : {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "group_by_item" : {
      "terms": {
        "field": "category"
      }
    }
  }
}

这将产生以下内容:

{
 ...
 "aggregations": {
    "group_by_category": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 1278,
      "buckets": [
        {
          "key": "Plane",
          "doc_count": 15482
        },
        {
          "key": "Bike",
          "doc_count": 10740
        },
        {
          "key": "Car",
          "doc_count": 9566
        }
      ]
    }
  }
}

我想归为新类别,可以是“飞什么”和“什么驱动”:

{
 ...
 "aggregations": {
    "group_by_category": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 1278,
      "buckets": [
        {
          "key": "Flies",
          "doc_count": 15482
        },
        {
          "key": "Drives",
          "doc_count": 20306
        }
      ]
    }
  }
}

0 个答案:

没有答案