Count, Aggregation, Frequency: Bit Stumped

Wonder if anyone can help?

I have the following query:

"from": 0,
"sort": [
"fields": [
"query": {
"query_string": {
"fields": [
"query": "("green socks" OR "red socks") AND NOT ("yellow" OR
"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

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,


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
To view this discussion on the web visit
For more options, visit