Elasticsearch术语聚合结果计数

时间:2017-02-06 11:32:47

标签: elasticsearch aggregation

我需要查询某个月的网店数据库中的返回客户数量。

我绑定了以下查询(订单超过1个的客户):

GET webshop/orders/_search
{
  "size": 0, 
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "created_at": {
              "gte": "2017-01-01",
              "lte": "2017-01-31"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "orders_count": {
      "terms": {
        "size": 0, 
        "field": "user_email",
        "min_doc_count": 2
      }
    }
  }
}

结果是这样的:

{
  "took": 22,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 12,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "orders_count": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "email@gmail.com",
          "doc_count": 12
        },...
      ]
    }
  }
}

如何更改查询以获取返回的桶数?

0 个答案:

没有答案