elasticsearch - Selecting all the results from a bucket using TopHits aggregation -
i using tophits aggregation on terms aggregation fetch records shown in below query.
{ "aggregations" : { "group by" : { "terms" : { "field" : "city" }, "aggregations" : { "top" : { "top_hits" : { "size" : 200 } }}}}
i want fetch records present in bucket instead of top 200 records, value of size increases query time increases same indexed data (for same number of records).
so can not set size value randomly large number hampering querying time.
is there way achieve same efficiently ?
thanks.
in elastic search size having limitations default returns 10
documents if want increase documents size
values increase.
let's check this example in case
if deep pagination , size — e.g. ?size=10&from=10000 — is inefficient (in example) 100,000 sorted results have retrieved each shard , resorted in order return 10 results. process has repeated every page requested.
so case should use scroll api because of
the scroll api keeps track of results have been returned , able return sorted results more efficiently deep pagination. however, sorting results (which happens default) still has cost.
in case should use scan , scroll below :
curl - s - xget localhost: 9200 / logs / syslogs / _search ? scroll = 10 m & search_type = scan ' { "aggregations": { "group by": { "terms": { "field": "city" }, "aggregations": { "top": { "top_hits": { "size": 200 } } } } } }'
above query return scroll id
pass scroll id below
curl -xget 'localhost:9200/_search/scroll?scroll=1m' -d 'scroll id '
Comments
Post a Comment