I use the following simple query to search across documents in my Elastic index:
{
"query": { "query_string": { "query": "*test*" } },
"aggregations": {
"myaggregation": {
"terms": { "field": "myField.raw", "size": 0 }
}
}
}
This returns me the number of documents per distinct value of myField.raw
.
Since I'm interested into all actual documents than the total number, I tried to add the following top_hits
sub aggregation:
{
"query": { "query_string": { "query": "*test*" } },
"aggregations": {
"myaggregation": {
"terms": { "field": "myField.raw", "size": 0 },
"aggregations": {
"hits": {
"top_hits": { "size": 2000000 }
}
}
}
}
}
This ugly usage of top_hits
works, but is slow as hell.
Is there any proper way to fetch the actual documents for each bucket after doing the term
aggregation?
top_hits
, but it returns 100 hits per bucket, and i have 1 million buckets. Suppose also mysize + from
limit is the default 10000, then can I get all the hits for all the buckets? – Kubis