PUT my-data-stream/_bulk
{"create":{}}
{"timestamp":"2022-05-06T18:25:42","search_term":"hello", "counter": 10}
{"create":{}}
{"timestamp":"2022-05-06T18:25:42","search_term":"bye", "counter": 5}
{"create":{}}
{"timestamp":"2022-05-06T17:25:42","search_term":"hello", "counter": 9}
{"create":{}}
{"timestamp":"2022-05-06T17:25:42","search_term":"bye", "counter": 7}
{"create":{}}
{"timestamp":"2022-05-06T16:25:42","search_term":"hello", "counter": 5}
{"create":{}}
{"timestamp":"2022-05-06T16:25:42","search_term":"bye", "counter": 2}
给定上面的数据集。我想排序(DESC)的搜索词的计数器的总和大于一个特定的时间戳。
例如:对于大于2022-05-06T16:35:42
的时间戳(前4个记录)。结果应为
Hello, 19 (10 + 9)
Bye, 12 (5 + 7)
2条答案
按热度按时间f45qwnt81#
Tldr;
可以在聚合中使用
order
对数据进行排序。根据此处的文档
在这种情况下,存储桶按实际术语值排序,如关键字按字典顺序排序或数字按数字顺序排序。这种排序在升序和降序方向上都是安全的,并且生成准确的结果。
溶液
hmae6n7t2#
我使用了一个按日期过滤器,然后将结果聚集。
结果: