IT박스

10 개가 아닌 모든 Elasticsearch 집계 결과 / 버킷 표시

itboxs 2020. 6. 22. 08:08
반응형

10 개가 아닌 모든 Elasticsearch 집계 결과 / 버킷 표시


집계에 모든 버킷을 나열하려고하지만 처음 10 개만 표시하는 것 같습니다.

내 검색 :

curl -XPOST "http://localhost:9200/imoveis/_search?pretty=1" -d'
{
   "size": 0, 
   "aggregations": {
      "bairro_count": {
         "terms": {
            "field": "bairro.raw"
         }
      }
   }
}'

보고:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 16920,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "bairro_count" : {
      "buckets" : [ {
        "key" : "Barra da Tijuca",
        "doc_count" : 5812
      }, {
        "key" : "Centro",
        "doc_count" : 1757
      }, {
        "key" : "Recreio dos Bandeirantes",
        "doc_count" : 1027
      }, {
        "key" : "Ipanema",
        "doc_count" : 927
      }, {
        "key" : "Copacabana",
        "doc_count" : 842
      }, {
        "key" : "Leblon",
        "doc_count" : 833
      }, {
        "key" : "Botafogo",
        "doc_count" : 594
      }, {
        "key" : "Campo Grande",
        "doc_count" : 456
      }, {
        "key" : "Tijuca",
        "doc_count" : 361
      }, {
        "key" : "Flamengo",
        "doc_count" : 328
      } ]
    }
  }
}

이 집계에 대해 10 개가 넘는 키가 있습니다. 이 예에서는 145 개의 키가 있으며 각 키의 개수를 원합니다. 버킷에 페이지 매김이 있습니까? 나는 그들 모두를 얻을 수 있습니까?

Elasticsearch 1.1.0을 사용하고 있습니다


크기 매개 변수는 검색어 예제의 매개 변수 여야합니다.

curl -XPOST "http://localhost:9200/imoveis/_search?pretty=1" -d'
{
   "size": 0,
   "aggregations": {
      "bairro_count": {
         "terms": {
            "field": "bairro.raw",
             "size": 0
         }
      }
   }
}'

이 문서에서 언급했듯이 버전 1.1.0 이상에서만 작동합니다

편집하다

@PhaedrusTheGreek 의견을 기반으로 답변을 업데이트합니다.

size:0카디널리티 필드 값이 높은 클러스터에서 발생하는 메모리 문제로 인해 설정 이 2.x 이상에서 더 이상 사용되지 않습니다. 여기 에서 github 이슈 에서 더 많은 것을 읽을 수 있습니다 .

It is recommended to explicitly set reasonable value for size a number between 1 to 2147483647.


How to show all buckets?

{
  "size": 0,
  "aggs": {
    "aggregation_name": {
      "terms": {
        "field": "your_field",
        "size": 10000
      }
    }
  }
}

Note

  • "size":10000 Get at most 10000 buckets. Default is 10.

  • "size":0 In result, "hits" contains 10 documents by default. We don't need them.

  • By default, the buckets are ordered by the doc_count in decreasing order.


Why do I get Fielddata is disabled on text fields by default error?

Because fielddata is disabled on text fields by default. If you have not wxplicitly chosen a field type mapping, it has the default dynamic mappings for string fields.

So, instead of writing "field": "your_field" you need to have "field": "your_field.keyword".


Increase the size(2nd size) to 10000 in your term aggregations and you will get the bucket of size 10000. By default it is set to 10. Also if you want to see the search results just make the 1st size to 1, you can see 1 document, since ES does support both searching and aggregation.

curl -XPOST "http://localhost:9200/imoveis/_search?pretty=1" -d'
{
   "size": 1,
   "aggregations": {
      "bairro_count": {
         "terms": {
             "field": "bairro.raw",
             "size": 10000

         }
      }
   }
}'

참고URL : https://stackoverflow.com/questions/22927098/show-all-elasticsearch-aggregation-results-buckets-and-not-just-10

반응형