Filters 집계
Filters 집계
filters 집계는 각각 이름 붙은 또는 익명의 필터 쿼리와 연결된 여러 버킷을 만들어요. 모든 문서는 모든 필터에 대해 평가되며, 문서가 둘 이상의 필터와 일치하면 여러 버킷에 들어갈 수 있어요. 이는 단일 버킷만 생성하는 filter 집계와 다르다는 점이에요.
출처: 문서
본문
파라미터 (Parameters)
filters 집계는 다음 파라미터를 받아요.
| 파라미터 | 필수/선택 | 데이터 타입 | 설명 |
|---|---|---|---|
| filters | 필수 | Object 또는 Array | 필터 정의. 레이블이 있는 버킷에는 이름 붙은 키를 가진 객체를, 익명(위치 기반) 버킷에는 배열을 제공해요. |
| other_bucket | 선택 | Boolean | true면 어떤 필터와도 일치하지 않은 모든 문서를 담는 버킷을 추가해요. 기본값은 false예요. |
| other_bucket_key | 선택 | String | other 버킷의 키 이름. 이 값을 설정하면 other_bucket이 암시적으로 활성화돼요. 기본값은 _other_예요. |
예제: 이름 붙은 필터 (Named filters)
filters를 객체로 제공하면 각 키가 응답의 버킷 이름이 돼요. 다음 예제는 전자상거래 주문을 세 가지 가격 등급으로 그룹화해요:
GET /opensearch_dashboards_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"price_ranges": {
"filters": {
"filters": {
"budget": { "range": { "taxful_total_price": { "lte": 50 } } },
"mid_range": { "range": { "taxful_total_price": { "gt": 50, "lte": 100 } } },
"premium": { "range": { "taxful_total_price": { "gt": 100 } } }
}
}
}
}
}
예제: 익명 필터 (Anonymous filters)
filters를 배열로 제공하면 버킷이 배열과 같은 순서로 반환돼요. 다음 예제는 익명 필터를 사용해요:
GET /opensearch_dashboards_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"price_ranges": {
"filters": {
"filters": [
{ "range": { "taxful_total_price": { "lte": 50 } } },
{ "range": { "taxful_total_price": { "gt": 50, "lte": 100 } } }
]
}
}
}
}
예제: Other 버킷 (Other bucket)
other_bucket 파라미터는 정의된 필터 중 어느 것과도 일치하지 않은 모든 문서를 포착해요. 다음 예제는 other_bucket_key를 사용해 catch-all 버킷에 커스텀 이름을 지정해요:
GET /opensearch_dashboards_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"price_ranges": {
"filters": {
"other_bucket": true,
"other_bucket_key": "all_others",
"filters": {
"budget": { "range": { "taxful_total_price": { "lte": 50 } } },
"premium": { "range": { "taxful_total_price": { "gt": 100 } } }
}
}
}
}
}
예제 응답 (Example response)
다음 응답은 other bucket 예제에 해당해요:
{
"took": 3,
"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": {
"price_ranges": {
"buckets": {
"budget": {
"doc_count": 1633
},
"premium": {
"doc_count": 950
},
"all_others": {
"doc_count": 2092
}
}
}
}
}
응답 본문 필드 (Response body fields)
| 필드 | 데이터 타입 | 설명 |
|---|---|---|
| buckets | Object 또는 Array | 이름 붙은 필터를 사용하면 이름 붙은 키를 가진 객체, 익명 필터를 사용하면 객체의 배열. |
| buckets. |
Integer | 이 버킷의 필터와 일치하는 문서 수. |