I want to do a query that returns documents that belong to an aggregation with a specific size.
For example, if I have a field called "category" and do a term aggregation I will get buckets. I want to return documents that belong to an aggregation that have a bucket size between a specific range. How would I do that?
I guess you mean you want the documents inside the buckets that have a certain size range.
With the bucket selector and the "_count" field, you could get the buckets that have the wanted size:
{ "query" : { "match_all" : {} },
"aggs": { "categories": {
"terms": {"field": "category", "size":20},
"aggs": { "my_bucket_selection": { "bucket_selector" : {"buckets_path" : {"count": "_count"},
"script": "params.count>10000 &¶ms.count<100000"}
}
}
}
}
}
After that, one way I know of for retrieving the documents of a specific bucket is to do a query: query the document that have "category"=<bucket_key>
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.