{ "query": { "match": { "text": query } }, "size": 5, "aggs": { "bestDocs": { "sampler": { "field": "cluster", "shard_size": 1 }, "aggs": { "bestBuckets": { "terms": { "field": "cluster", "size": 5 } } } } } }

Using the simple query I get a bunch of documents where each document has a bucket id. I am trying to use sampler aggregation to get the buckets ids in the sequence they appear in the general query.

But when I run the above query I get buckets in ascending order and they are not even the ones that I get from the general query.

E.g.

{ "took": 4, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 959, "max_score": 1.841992, "hits": [ { "_source": { "cluster": "22570", "text": "about 1.5 million veteran families live at the federal poverty level, including 634,000 below 50 percent of the federal poverty", } }, { "_source": { "cluster": "22570", "text": "about 1.5 million veteran families live at the federal poverty level, including 634,000 below 50 percent of the federal poverty", } }, { "_source": { "cluster": "22570", "text": "about 1.5 million veteran families live at the federal poverty level, including 634,000 below 50 percent of the federal poverty", } }, { "_source": { "cluster": "22570", "text": "about 1.5 million veteran families live at the federal poverty level, including 634,000 below 50 percent of the federal poverty", } }, { "_source": { "cluster": "12239", "text": "veterans and their families."</p><p>The Veterans' Compensation Cost-of-Living Adjustment Act of 2011 directs the Secretary of Veterans Affairs to increase the rates of veterans", } } ] }, "aggregations": { "bestDocs": { "doc_count": 5, "bestBuckets": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": 22185, "doc_count": 1 }, { "key": 22570, "doc_count": 1 }, { "key": 29615, "doc_count": 1 }, { "key": 32784, "doc_count": 1 }, { "key": 43351, "doc_count": 1 } ] } } } }