# Exclude aggregation results that match all documents

**URL:** <https://discuss.elastic.co/t/exclude-aggregation-results-that-match-all-documents/20399>\
**Category:** Elasticsearch\
**Created:** [October 23, 2014, 12:20pm UTC](https://discuss.elastic.co/t/exclude-aggregation-results-that-match-all-documents/20399 "2014-10-23T12:20:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Pieper](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@Jan\_Pieper](https://discuss.elastic.co/u/Jan_Pieper)\
**Post date:** [October 23, 2014, 12:20pm UTC](https://discuss.elastic.co/t/exclude-aggregation-results-that-match-all-documents/20399/1 "2014-10-23T12:20:42Z")

</div>

Hi guys,

I am not very familiar with aggregations and filtering in ElasticSearch, so  
I hope you can help me with my problem.

_Scenario:_

A user visits our website and is searching for a specific product. He  
clicks to the search field and types a specifc string. Then hit clicks on  
"Search" and gets a list of search results based on his query.

The user wants to filter the products by a specific feature. He selects  
"1024x768" as screen resolution and gets a list of products with the screen  
resolution "1024x768". Now he wants to get only products that have the  
screen resolution "1024x768" and "VGA cable".

This is quite comparable to the search and filtering mechanism you can find  
at [amazon.com](http://amazon.com).

_Problem:_

After some filtering steps, the products are quite similiar and share most  
of the features BUT some features aren't available for all of these  
products.

Is there a way to filter out all features that are available for all  
products to get only a list of features that are available for some of  
these products to be able to decrease the amount of products in the next  
step?

_Example document:_

{ "segments": [ {  
"id": 1,  
"name": "Segment One",  
"features": [  
{  
"id": 1,  
"name": "Feature One"  
},  
{  
"id": 2,  
"name": "Feature Two"  
}  
]  
},  
{  
"id": 2,  
"name": "Segment Two",  
"features": [  
{  
"id": 3,  
"name": "Feature Three"  
}, {  
"id": 4,  
"name": "Feature Four"  
}  
]  
}  
] }

_Current example query:_

{  
"query": {  
"filtered": {  
"query": {  
"match": "Monitor"  
},  
"filter": {  
"and": [  
{  
"term": {  
"segments.features.id": 3  
}  
}  
]  
}  
}  
},  
"aggs": {  
"features": {  
"terms": {  
"lang": "groovy",  
"script": "strs = new ArrayList(); for (s in  
doc['segments.features.id']) { strs.add(s.toString()); }; return strs;",  
"exclude": "3"  
}  
}  
}  
}

Regards,  
Jan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/32ebd1f4-7e58-4261-9b8d-b6ceeddfdfc1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/32ebd1f4-7e58-4261-9b8d-b6ceeddfdfc1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:54am UTC](https://discuss.elastic.co/t/exclude-aggregation-results-that-match-all-documents/20399/2 "2017-07-06T00:54:14Z")

</div>

Closed on July 6, 2017, 12:54am UTC


