Ber*_*ant 6 elasticsearch elasticsearch-dsl elasticsearch-query elasticsearch-aggregation elasticsearch-5
具有Elasticsearch代表一个亲子结构order与order_revision孩子我要生成的直方图price显示的总和quantity.
{
"_type": "order",
"_id": "1063220887",
"_score": 1,
"_source": {
"order_id": "1063220887",
"product_id": "10446350",
"timestamp": 1462713302000
}
}
{
"_type": "order_revision",
"_id": "10234234",
"_parent": "1063220887",
"_source": {
"price": 9,
"quantity": 3,
"revision": 361,
"timestamp": 1462712196000
}
}
Run Code Online (Sandbox Code Playgroud)
以下聚合基本上有效,但返回所有现有修订的总和.
{
"aggs": {
"orders": {
"filter": {
"has_parent": {
"parent_type": "order"
}
},
"aggs": {
"quantity_per_price": {
"histogram": {
"field": "price",
"interval": 1
}
"aggs": {
"sum": {"field": quantity"}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在最终版本中,它应该只返回每个订单quantity的最新版本(具有最高/最新版本timestamp)的字段总和.我不完全确定如何提出这样的聚合分组,order_id并且只选择最新的子代,我也不确定这种父子结构是否最适合对这些数据进行建模.
| 归档时间: |
|
| 查看次数: |
165 次 |
| 最近记录: |