我有以下结构的索引
item_id: unique item id
sale_date: date of the date
price: price of the sale wrt the date
我想创建每件商品最新销售价格的直方图。聚合术语 item_id
和最近或最新 price
我的第一个选择是 term
聚合 item_id
并从 top_hits
size 1 order 中选择
price
sale_datedesc
并在 python 端创建直方图。
但是。
因为数据在一个月内有数百万条记录。及时下载所有源
来执行直方图是不可行的。
注意:有些元素每天出售,有些则在不同的时间间隔出售。这使得只选择最新的 sale_date
更新:
输入:基于商品的销售时间序列数据。
输出:商品数量的直方图位于某个价格范围内,与最新信息相关
最佳答案
我已经转过身来,我使用了类似的情况,您可以使用 max
类型的 date
聚合,并且可以根据 order
聚合嵌套的 aggs
值,就像:
"aggs": {
"item ID": {
"terms": {
"field": "item_id",
"size": 10000
},
"aggs": {
"price": {
"terms": {
"field": "price",
"size": 1,
"order": {
"sale_date": "desc"
}
},
"aggs": {
"sale_date": {
"max": {
"field": "sale_date"
}
}
}
}
}
}
}
希望这对您有所帮助,如果它对您有用,希望您能告诉我。
关于python - Elasticsearch 中的自定义直方图聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59472730/