Terms Aggregation Restricted to Top Matches?

Hi,

Is it possible to do a Terms aggregation in Elasticsearch, but restricted
to the top N matching documents?
I'm aware of the top_hits aggregator, but it does not allow sub
aggregations.
So while I can get the top N matches per term, I can't find a way to get
the terms of the top N matches.

My current query is something like:

GET /myindex/mydoc/_search
{
"size": 0,
"query": {"match": {
"field_to_search": "some search string"
}}
,"aggs": {
"term_aggregation": {
"terms": {
"field": "Tags",
"size": 0,
"order": {
"summed_score": "desc"
}
},
"aggs":{"summed_score":{"sum":{"script":"doc.score"}} }
}
}
}

which aggregates the scores of ALL matching documents by terms in the Tags
field.

Is there any way to do what I want?

Thanks

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8a3df48e-2551-45db-91e7-d827f141dcb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Working on it ... Aggregations: new “Sampler” provides a filter for top-scoring docs by markharwood · Pull Request #8191 · elastic/elasticsearch · GitHub

On Wednesday, December 10, 2014 4:59:19 PM UTC, Chris H wrote:

Hi,

Is it possible to do a Terms aggregation in Elasticsearch, but restricted
to the top N matching documents?
I'm aware of the top_hits aggregator, but it does not allow sub
aggregations.
So while I can get the top N matches per term, I can't find a way to get
the terms of the top N matches.

My current query is something like:

GET /myindex/mydoc/_search
{
"size": 0,
"query": {"match": {
"field_to_search": "some search string"
}}
,"aggs": {
"term_aggregation": {
"terms": {
"field": "Tags",
"size": 0,
"order": {
"summed_score": "desc"
}
},
"aggs":{"summed_score":{"sum":{"script":"doc.score"}} }
}
}
}

which aggregates the scores of ALL matching documents by terms in the Tags
field.

Is there any way to do what I want?

Thanks

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/574a1596-e705-405c-868b-bb73d3452372%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.