14.ES|Post Filter
Post Filterとは、検索結果とAggregations(集計結果)の両方に対して、Filterをかける機能。
- サンプルクエリ
GET /shirts/_search { "query": { "bool": { "filter": { "term": { "brand": "gucci" } …① } } }, "aggs": { "colors": { "terms": { "field": "color" } …② }, "color_red": { "filter": { "term": { "color": "red" } …③ }, "aggs": { "models": { "terms": { "field": "model" } …④ } } } }, "post_filter": { "term": { "color": "red" } } }
①.The main query now finds all shirts by Gucci, regardless of color.
②.The colors agg returns popular colors for shirts by Gucci.
③.The color_red agg limits the models sub-aggregation to red Gucci shirts.
④.Finally, the post_filter removes colors other than red from the search hits.
- Elasticsearch公式/「Post filter」 www.elastic.co