在elasticsearch中,我们正在将动态Map移到静态Map。所以我们重新索引我们的旧索引。我们删除了父子关系,而且以前在旧索引中有不同的类型,现在在新索引中只有一个文档类型。
问题来了。
旧es查询
{
index: 'rides',
filterPath: "aggregations.avg_difference",
body: {
size: 0,
query: {
has_parent: {
parent_type: 'ride_details',
query: {
bool: {
must: [
{
match_phrase: {
ride_status: 'Ride Completed',
},
},
],
},
},
},
},
aggs: {
ride_agg: {
terms: {
field: 'ride_details_id',
size: 2147483647,
},
aggs: {
only_driver_confirmed: {
filter: {
term: {
status: 'Driver Confirmed',
},
},
aggs: {
min_time: {
min: {
field: 'createdAt',
},
},
},
},
only_arrived: {
filter: {
term: {
status: 'Driver Arrived',
},
},
aggs: {
min_time: {
min: {
field: 'createdAt',
},
},
},
},
difference: {
bucket_script: {
buckets_path: {
min_driver_confirmed: 'only_driver_confirmed>min_time',
min_only_arrived: 'only_arrived>min_time',
},
script: 'params.min_only_arrived - params.min_driver_confirmed',
},
},
},
},
avg_difference: {
avg_bucket: {
buckets_path: 'ride_agg>difference',
},
},
},
},
};
此新查询
{
index: 'rides_modified',
filterPath: "aggregations.avg_difference",
body: {
size: 0,
query: {
bool: {
must: [
{
match: {
"index_type": "audit_log"
}
}
]
}
},
aggs: {
ride_agg: {
terms: {
field: "ride_details_id",
size: 2147483647
},
aggs: {
only_driver_confirmed: {
filter: {
term: {
status: "Driver Confirmed"
}
},
aggs: {
min_time: {
min: {
field: "createdAt"
}
}
}
},
only_arrived: {
filter: {
term: {
status: "Driver Arrived"
}
},
aggs: {
min_time: {
min: {
field: "createdAt"
}
}
}
},
difference: {
bucket_script: {
buckets_path: {
min_driver_confirmed: "only_driver_confirmed>min_time",
min_only_arrived: "only_arrived>min_time"
},
script: "params.min_only_arrived - params.min_driver_confirmed"
}
}
}
},
avg_difference: {
avg_bucket: {
buckets_path: "ride_agg>difference"
}
}
}
},
};
我们期望两个查询的结果应该相同。但结果不同。聚合查询可以提供大约的结果吗?
暂无答案!
目前还没有任何答案,快来回答吧!