【发布时间】:2020-09-05 02:49:04
【问题描述】:
我正在尝试在下面的示例中复制 filtered aggregation: 在这里,我试图过滤与管道名称匹配的文档,并在这些管道中找到要执行的最长持续时间。
{
"_source" : {"excludes": ["stderr"]},
"aggs" : {
"max_duration_filtered" : {
"filter" : {
"term": {
"pipeline": "{name_of_pipeline}"
}
},
"aggs" : {
"max_duration" : {
"max" : {
"field" : "duration"
}
}
}
}
}
}
调用它会返回以下输出以及 1 个命中(我也传入 size=1)
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 63643,
"max_score" : 1.0,
"hits" : [
{
"_index" : "{name-of-index}",
"_type" : "raw_data",
"_id" : "{an-id}",
"_score" : 1.0,
"_source" : {
"duration" : 42.8,
"pipeline" : "{a-different-pipeline}",
"buildNumber" : {build-number-integer}
}
}
]
},
"aggregations" : {
"max_duration_filtered" : {
"doc_count" : 0,
"max_duration" : {
"value" : null
}
}
}
}
我真的很想了解为什么最大持续时间值为空。看来我非常仔细地反映了文档中的内容。有什么我可以尝试解决的问题吗? 谢谢!
【问题讨论】:
-
doc_count 为 0,表示您过滤的名称不在查询结果中
-
您的过滤器不适用于命中,而仅适用于聚合。你能解释一下你对结果的期望吗?
-
@jaspreetchahal -> 我确保通过查询 => `` { "_source" : {"excludes": ["stderr"]}, "query": { "match_all" : {} }, "size": 40 } ``` 并在数据中找到了管道的名称
-
@Val 我有数据,其中包含管道列表以及它们执行所需的相应时间。我正在尝试按管道类型过滤数据,然后找到任何这些管道执行所需的最长时间。基本上按管道名称过滤,然后在过滤集中找到最大持续时间。
标签: python elasticsearch elasticsearch-aggregation