仅返回聚合查询的存储桶大小-Elasticsearch

时间:2019-04-15 14:23:08

标签: elasticsearch nosql elasticsearch-aggregation

我正在对Elasticsearch 2.1使用聚合查询,这是我的查询:

"aggregations": {
        "atendimentos": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "1a92d5c0-d542-4f69-aeb0-42a467f6a703",
                    "doc_count": 12
                },
                {
                    "key": "4e30bf6d-730d-4217-a6ef-e7b2450a012f",
                    "doc_count": 12
                }.......

返回是这样的:

buckets_size: 40000

它返回40000个存储桶,因此在此聚合中有很多存储桶,我只想返回存储桶的大小,但是我想要这样的东西:

@Aspect
public class MyCustomAsspect{

    @AfterReturning(
            pointcut="execution(public * *(..)) and @annotation(MyCustomAnnotation)",
            returning="retVal")
    public void publishMessage(JoinPoint jp, Object retVal) throws Throwable {


    }
}

伙计们,如何只返回水桶大小?

好,谢谢大家。

2 个答案:

答案 0 :(得分:0)

尝试此查询:

for

它可能会返回类似的内容:

POST index/_search
{
  "size": 0,
  "aggs": {
    "atendimentos": {
      "terms": {
        "field": "_parent"
      }
    },
    "count":{
      "cardinality": {
        "field": "_parent"
      }
    }
  }
}

编辑:此处有更多信息-https://www.elastic.co/guide/en/elasticsearch/reference/2.1/search-aggregations-metrics-cardinality-aggregation.html

答案 1 :(得分:0)

{
    "aggs" : {
        "type_count" : {
            "cardinality" : {
                "field" : "type"
            }
        }
    }
}

详细了解Cardinality Aggregation