Filter 집계
Filter 집계
filter 집계는 지정된 쿼리와 일치하는 모든 문서를 담은 단일 버킷을 만들어요. match, term, range, bool 등 어떤 쿼리 절이든 필터 역할을 할 수 있어요. filter 집계 안에 중첩된 하위 집계는 일치하는 문서에 대해서만 동작하므로, 비용이 많이 드는 계산을 관련 하위 집합으로 범위를 한정할 때 유용해요.
여러 개의 이름 붙은 버킷으로 동시에 문서를 필터링하려면 filters 집계를 참고하세요.
출처: 문서
본문
예제 (Example)
다음 예제는 range 필터 안에 avg 하위 집계를 감싸 $50 미만의 모든 주문에 대한 평균 주문 금액을 계산해요:
GET /opensearch_dashboards_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"low_value": {
"filter": {
"range": {
"taxful_total_price": {
"lte": 50
}
}
},
"aggs": {
"avg_amount": {
"avg": {
"field": "taxful_total_price"
}
}
}
}
}
}
예제 응답 (Example response)
{
"took": 43,
"timed_out": false,
"terminated_early": true,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4675,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"low_value": {
"doc_count": 1633,
"avg_amount": {
"value": 38.363175998928355
}
}
}
}
응답 본문 필드 (Response body fields)
| 필드 | 데이터 타입 | 설명 |
|---|---|---|
| doc_count | Integer | 필터 쿼리와 일치한 문서 수. |