elasticsearch distinct查询只返回10个桶

时间:2017-03-17 17:56:00

标签: elasticsearch

我正在尝试获取elasticsearch中字段的所有不同值,但我只能获得10个桶。

我设置了这样的查询:

GET /sdpjmx/kafkajmx/_search
{
"size": 0,
"aggs" : {
    "topics" : {
        "terms" : { "field" : "kafka_topic" }
    }
}}

即使将size设置为0,我仍然只能回到10。

结果如下:

{
  "took": 11,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "failed": 0
  },
  "hits": {
    "total": 948380,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "topics": {
      "doc_count_error_upper_bound": 3597,
      "sum_other_doc_count": 886819,
      "buckets": [
        {
          "key": "__consumer_offsets",
          "doc_count": 10777
        },
        {
          "key": "EVENT_ONE",
          "doc_count": 4367
        },
        {
          "key": "ERROR_AUTH",
          "doc_count": 4365
        },
        {
          "key": "topic zds",
          "doc_count": 4364
        },
        {
          "key": "topicabs",
          "doc_count": 4360
        },
        {
          "key": "dynamictopic1",
          "doc_count": 3827
        },
        {
          "key": "connect-a",
          "doc_count": 3824
        },
        {
          "key": "topic12",
          "doc_count": 3820
        },
        {
          "key": "service_qa",
          "doc_count": 3820
        },
        {
          "key": "topic ad",
          "doc_count": 3819
        }
      ]
    }
  }
}

2 个答案:

答案 0 :(得分:1)

尝试在术语聚合中添加尺寸参数:

{ "size": 0, "aggs" : { "topics" : { "terms" : { "field" : "kafka_topic", "size": 1000 } } } } name

答案 1 :(得分:1)

GET /sdpjmx/kafkajmx/_search
{
"size": 0, //<-- This size is for query results and not agg results
"aggs" : {
    "topics" : {
        "terms" : { "field" : "kafka_topic" },
        "size" : 0 //<-- it will return all aggregation terms
    }
}}