# Post Filter access aggregation values

**URL:** https://discuss.elastic.co/t/post-filter-access-aggregation-values/51164
**Category:** Elasticsearch
**Created:** [May 27, 2016, 2:33pm UTC](https://discuss.elastic.co/t/post-filter-access-aggregation-values/51164 "2016-05-27T14:33:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kumarts](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@kumarts](https://discuss.elastic.co/u/kumarts)
#### Post date: [May 27, 2016, 2:33pm UTC](https://discuss.elastic.co/t/post-filter-access-aggregation-values/51164/1 "2016-05-27T14:33:22Z")

</div>

Hi there  
I need help to understand how to run post filter scripts to show only results with cardinality \> 2.  
{ "aggs" : { "products\_items" : { "term": { "field": "product" } },  
"aggs" : { "distinct\_pricing" : { "cardinality" : { "field" : "price\_types" } } },  
"post\_filter": {"script": {"script": "distinct\_pricing[price\_type].value \> 2 "}}} } } }

Basically with we have products\_items with many pricing types ;eg for VIP customers, VVIP customers & normal customers then we are interested to show only those items.

product\_items price\_type  
001 VIP  
001 VVIP  
001 ORD  
002 ORD  
003 VIP  
003 VVIP  
004 VIP  
005 ORD  
005 VIP

Appreciate any help guidance.

Cheers

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [May 30, 2016, 2:07pm UTC](https://discuss.elastic.co/t/post-filter-access-aggregation-values/51164/2 "2016-05-30T14:07:59Z")

</div>

`post_filter` is only about top hits, not aggregations. What you are looking after is the bucket selector aggregation: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html)

---

<div class="post-metadata">

### Author: ![kumarts](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@kumarts](https://discuss.elastic.co/u/kumarts)
#### Post date: [May 31, 2016, 2:44am UTC](https://discuss.elastic.co/t/post-filter-access-aggregation-values/51164/3 "2016-05-31T02:44:51Z")

</div>

Adrien Grand  
Thank you very much, Finally got it working -  
I have pasted the sample query hopefully will be useful to others who encounter such a problem.  
{  
"aggs": {"ID1": {"terms": {"field": "cars"},  
"aggs": {"ID2": {"cardinality": {"field": "roadaccessed"}},  
"bucketfilter": {"bucket\_selector": { "buckets\_path" : { "cnt":"ID2"}, "script": "cnt\>5" }}}}} }

This will give you a list of cars that have accessed more than 5 roads

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 10:47pm UTC](https://discuss.elastic.co/t/post-filter-access-aggregation-values/51164/4 "2017-07-05T22:47:53Z")

</div>


