ElasticSearch - 使用嵌套查询进行查询+聚合与聚合

时间:2016-07-06 20:48:57

标签: elasticsearch

query + aggregationquery appart中的aggregation之间的响应略有不同,是否有任何性能差异? (总命中和额外层)。

我在网址中使用?query_type=count来跳过文档检索阶段。

查询+聚合

{
  "query": {
    "match": {
      "_all": {
        "query": "Plastic"
      }
    }
  },
  "aggs": {
    "count_by_type": {
      "terms": {
        "field": "_type"
      }
    }
  }
}

# Response
{
  "hits": {"total": 15},
  "aggregations": {
    "count_by_type": {
      "buckets":[
        {"key":"product","doc_count":15}
      ]
  }}}

在聚合内部查询

{
  "aggs": {
    "shop_stuff": {
      "filter": {
        "query": {
          "match": {
            "_all": {
              "query": "Plastic"
            }
          }
        }
      },
      "aggs": {
        "count_by_type": {
          "terms": {
            "field": "_type"
          }
        }
      }
    }
  }
}

# Response
{
  "hits": {"total":165},
  "aggregations": {
    "agg_stuff": {
      "doc_count":15,
      "count_by_type": {
        "buckets":[
          {"key":"product","doc_count":15}
        ]
}}}}

0 个答案:

没有答案