본문 바로가기

른록노트

[Elasticsearch] aggregation에서 doc_count말고 bucket의 개수만 구하는 방법+ 개수에 조건주는 방법 본문

DB/[Elasticsearch]

[Elasticsearch] aggregation에서 doc_count말고 bucket의 개수만 구하는 방법+ 개수에 조건주는 방법

른록 2017. 8. 25. 02:38
Hi,

is there a way to get just the count of buckets (not the count of docs,
which works i know) of an aggregation without receiving the whole buckets
content?

thx, Tom
- Show quoted text -

(질문한 양반 해석)
어그리게이션의 버킷의 개수만 구하는 방법이 있나요?(내가 알고있는 docs의 개수 말고 전체 내용 없이)

(해결법)

Rich Somerfieldat Dec 16, 2014 at 7:02 pm
Hi Tom,

I think the "Cardinality" aggregation is what you want.

e.g. :

{
   ...query...
},
"aggregations": {
   "totalUniqueUsers": {
     "cardinality": {
       "field": "username"
     }
   }
}

-Rich
- Show quoted text -


Cardinality란?
 
Cardinality Aggregationedit
A single-value metrics aggregation that calculates an approximate count of distinct values. Values can be extracted either from specific fields in the document or generated by a script.

Cardinality를 사용하면 distinct로 카운트값을 계산한다.
값은 문서의 특정 필드에서 추출하거나 스크립트로 생성 할 수 있습니다.






-버킷 개수에 제한 걸어주기

Table 12. bucket_selector Parameters

Parameter Name

Description

Required

Default Value

script

The script to run for this aggregation. The script can be inline, file or indexed. (see Scripting for more details)

Required

buckets_path

A map of script variables and their associated path to the buckets we wish to use for the variable (see buckets_path Syntaxedit for more details)

Required

gap_policy

The policy to apply when gaps are found in the data (see Dealing with gaps in the dataedit for more details)










참고사이트

http://grokbase.com/t/gg/elasticsearch/14cg0jk7px/aggregegation-buckets-count

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html

반응형
Comments