目标是 build an Elasticsearch index with only the most recent documents in groups of related documents 跟踪一些监控计数器和状态的当前状态 .
我制作了一个简单的 Elasticsearch aggregation query :
{
"size": 0,
"aggs": {
"group_by_monitor": {
"terms": {
"field": "monitor_name"
},
"aggs": {
"get_latest": {
"top_hits": {
"size": 1,
"sort": [
{
"timestamp": {
"order": "desc"
}
}
]
}
}
}
}
}
}
它将相关文档分组到存储桶中,并为每个存储桶选择最新文档 .
以下是我完成工作所需的不同想法:
-
直接使用聚合查询将结果推送到索引中,但似乎不可能:Is it possible to put the results of an ElasticSearch aggregation back into the index?
-
使用 Logstash Elasticsearch input plugin执行聚合查询而Elasticsearch output plugin推入索引,但似乎输入插件只查看
hits
字段并且无法处理聚合结果:Aggregation Query possible input ES plugin! -
使用 Logstash http_poller plugin来获取JSON文档,但它似乎不允许为HTTP请求指定正文!
-
使用 Logstash exec plugin来执行cURL命令来获取JSON,但这看起来非常麻烦,我的最后一招 .
-
使用NEST API构建一个基本应用程序,它将进行轮询,提取结果,清理它们并将结果文档注入目标索引,但我想避免添加一个新工具来维护 .
是否有一种相当复杂的方法来实现这一目标?
1 回答
编辑
logstash.conf
文件如下