Filtering, sorting and paginating by sub-aggregations in ElasticSearch 6
Here is the query without pagination:
{ "size":0, "query":{ "bool":{ "must":[ { "terms":{ "day":[ "20200530", "20200531", "20200532" ] } } ] } }, "aggs":{ "rooms":{ "nested":{ "path":"rooms" }, "aggs":{ "rooms":{ "terms":{ "field":"rooms.room_id", "min_doc_count":3, "order":{ "sum_price":"asc" } }, "aggs":{ "sum_price":{ "sum":{ "field":"rooms.rate" } }, "max_price":{ "bucket_selector":{ "buckets_path":{ "var1":"sum_price" }, "script":"params.var1 < 100" } } } } } } }}
Please note that the following variables should be changed for the desired results:
- day
- min_doc_count
- script in max_price