我对 ElasticSearch 很陌生,我想知道是否可以根据 restaurant_id 显示数据,然后显示确认订单的平均时间。例如,我有文件:
{ _index: "orders-development",
_type: "order",
_id: "4412917",
_score: 1,
_source: {confirm_duration: 5}
}
{ _index: "orders-development",
_type: "order",
_id: "4412917",
_score: 1,
_source: {confirm_duration: 4}
}
{ _index: "orders-development",
_type: "order",
_id: "4322923",
_score: 1,
_source: { confirm_duration: 12}
}
以上是存储在ES中的文档,现在我必须根据restaurant_id显示数据,然后是平均时间。所以现在我使用下面的代码并显示错误“原因”:“[terms] unknown field [avg], parser not found”
aggregations = {
avg_order_confirmation: {
terms: {
field: :restaurant_id,
size: 100,
avg: { field: :confirm_duration },
}
}
}