# Count, Aggregation, Frequency: Bit Stumped

**URL:** <https://discuss.elastic.co/t/count-aggregation-frequency-bit-stumped/23383>\
**Category:** Elasticsearch\
**Created:** [April 23, 2015, 9:38pm UTC](https://discuss.elastic.co/t/count-aggregation-frequency-bit-stumped/23383 "2015-04-23T21:38:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rolandino](https://avatars.discourse-cdn.com/v4/letter/r/e36b37/32.png) [@rolandino](https://discuss.elastic.co/u/rolandino)\
**Post date:** [April 23, 2015, 9:38pm UTC](https://discuss.elastic.co/t/count-aggregation-frequency-bit-stumped/23383/1 "2015-04-23T21:38:57Z")

</div>

Hi,  
Wonder if anyone can help?

I have the following query:

{  
"from": 0,  
"sort": [  
"\_score"  
],  
"fields": [  
"id",  
"title",  
"text"  
],  
"query": {  
"query\_string": {  
"fields": [  
"title",  
"text"  
],  
"query": "("green socks" OR "red socks") AND NOT ("yellow" OR  
"blue")"  
}  
},  
"size": 100  
}

This works fine and is great. What I would like to do now though, is take  
the documents identified by this query, and retrieve the number of  
documents that contained "green socks", and the number that contained "red  
socks".

So, essentially apply an aggregation (I think) to the articles identified  
by the "query": "("green socks" OR "red socks") AND NOT ("yellow" OR  
"blue")" query.

If this is an aggregation, what kind of aggregation is it?  
If it isn't, what kind of query should I run?

To be clear, what i'm looking for, is at the end of whatever I query I run  
I end up with:

"green socks": 10,  
"red socks": 13,

where 10 and 13 are the number of documents in the "("green socks" OR  
"red socks") AND NOT ("yellow" OR "blue")" result set that contain  
"green socks" at least once, and "red socks" at least once (respectively).

Any help v gratefully received,

Thanks,  
R

--  
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/f2731846-7536-44ab-9df6-808a5b0f1c34%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f2731846-7536-44ab-9df6-808a5b0f1c34%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:17am UTC](https://discuss.elastic.co/t/count-aggregation-frequency-bit-stumped/23383/2 "2017-07-06T00:17:59Z")

</div>

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


