【发布时间】:2019-08-30 03:39:06
【问题描述】:
我正在尝试进行 date_histogram 聚合以显示每个小时的 Duration 总和。
我有以下文件:
{
"EntryTimestamp": 1567029600000,
"Username": "johndoe",
"UpdateTimestamp": 1567029600000,
"Duration": 10,
"EntryID": "ASDF1234"
}
以下工作非常好,但我的问题是有时会出现多个文档具有相同的 EntryID。因此,理想情况下,我需要以某种方式添加 top_hits,并按 UpdateTimestamp 排序,因为我需要每个唯一 EntryID 的最后更新文档。但不确定如何将其添加到我的查询中。
{
"size": 0,
"query": {
"bool": {
"filter": [{
"range": {
"EntryTimestamp": {
"gte": "1567029600000",
"lte": "1567065599999",
"format": "epoch_millis"
}
}
}, {
"query_string": {
"analyze_wildcard": true,
"query": "Username.keyword=johndoe"
}
}
]
}
},
"aggs": {
"2": {
"date_histogram": {
"interval": "1h",
"field": "EntryTimestamp",
"min_doc_count": 0,
"extended_bounds": {
"min": "1567029600000",
"max": "1567065599999"
},
"format": "epoch_millis"
},
"aggs": {
"1": {
"sum": {
"field": "Duration"
}
}
}
}
}
}
【问题讨论】:
标签: elasticsearch