Elasticsearch:每月获取顶级嵌套文档,没有顶级重复项
Elasticsearch: get top nested doc per month without top level duplicates
我有一些基于时间的嵌套数据,我希望每月获得 plugins
的最大正负变化。我使用 Elasticsearch 5.3(和 Kibana 5.3)。
文档结构如下:
{
_id: "xxx",
@timestamp: 1508244365987,
siteURL: "www.foo.bar",
plugins: [
{
name: "foo",
version: "3.1.4"
},
{
name: "baz",
version: "13.37"
}
]
}
但是,对于每个 id (siteURL
),我每个月都有多个条目,我想只使用每个时间段的最新条目,以避免权衡不公平。
我试图通过使用以下聚合来解决这个问题:
{
"aggs": {
"normal_dates": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": "now-1y/d",
"to": "now"
}
]
},
"aggs": {
"date_histo": {
"date_histogram": {
"field": "@timestamp",
"interval": "month"
},
"aggs": {
"top_sites": {
"terms": {
"field": "siteURL.keyword",
"size": 50000
},
"aggs": {
"top_plugin_hits": {
"top_hits": {
"sort": [
{
"@timestamp": {
"order": "desc"
}
}
],
"_source": {
"includes": [
"plugins.name"
]
},
"size": 1
}
}
}
}
}
}
}
}
}
}
现在我每个月都会收到最新的网站及其插件。接下来,我想将数据翻转过来,并获取每月出现的插件和出现的次数。然后我会使用 serial_diff 来比较月份。
但是,我不知道如何从聚合到串行差异,即将数据翻转过来。
非常欢迎任何帮助
PS:如果我能在 Kibana 5.3 中获得它,我将获得额外的荣誉 table...
事实证明无法进一步聚合 top_hits
查询。
我最终将已发布查询的结果加载到 Python 并使用 Python 进行进一步处理和可视化。
我有一些基于时间的嵌套数据,我希望每月获得 plugins
的最大正负变化。我使用 Elasticsearch 5.3(和 Kibana 5.3)。
文档结构如下:
{
_id: "xxx",
@timestamp: 1508244365987,
siteURL: "www.foo.bar",
plugins: [
{
name: "foo",
version: "3.1.4"
},
{
name: "baz",
version: "13.37"
}
]
}
但是,对于每个 id (siteURL
),我每个月都有多个条目,我想只使用每个时间段的最新条目,以避免权衡不公平。
我试图通过使用以下聚合来解决这个问题:
{
"aggs": {
"normal_dates": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": "now-1y/d",
"to": "now"
}
]
},
"aggs": {
"date_histo": {
"date_histogram": {
"field": "@timestamp",
"interval": "month"
},
"aggs": {
"top_sites": {
"terms": {
"field": "siteURL.keyword",
"size": 50000
},
"aggs": {
"top_plugin_hits": {
"top_hits": {
"sort": [
{
"@timestamp": {
"order": "desc"
}
}
],
"_source": {
"includes": [
"plugins.name"
]
},
"size": 1
}
}
}
}
}
}
}
}
}
}
现在我每个月都会收到最新的网站及其插件。接下来,我想将数据翻转过来,并获取每月出现的插件和出现的次数。然后我会使用 serial_diff 来比较月份。
但是,我不知道如何从聚合到串行差异,即将数据翻转过来。
非常欢迎任何帮助
PS:如果我能在 Kibana 5.3 中获得它,我将获得额外的荣誉 table...
事实证明无法进一步聚合 top_hits
查询。
我最终将已发布查询的结果加载到 Python 并使用 Python 进行进一步处理和可视化。