elasticsearch - Elasticsearch,查找不匹配包含值的文档的文档
问题描述
编辑:简化了我的问题
我将事件日志流式传输到单个弹性搜索索引“日志”中。
这些事件日志中的每一个都代表某个长时间运行的进程中的单个事件。事件日志有一个状态,其值为 queued->init->running->finished。
现在我想查询我的索引以查找正在运行的作业……但如果我搜索 status="running",我还将获得稍后完成的作业。作为一个人,我会寻找带有“正在运行”事件但没有“已完成”事件的日志。
假设我必须耙树叶,打扫房子,然后吃午饭。我的事件日志看起来像:即
{job: "rake leaves" status: "queued"}
{job: "clean house" status: "queued"}
{job: "eat lunch" status: "queued"}
{job: "rake leaves" status: "started"}
{job: "rake leaves" status: "running"}
{job: "rake leaves" status: "finished"}
{job: "clean house" status: "started"}
{job: "clean house" status: "finished"}
{job: "clean house" status: "running"}
{job: "eat lunch" status: "started"}
{job: "eat lunch" status: "running"}
如何找到尚未完成的正在运行的作业?在这种情况下,吃午饭是唯一的工作。我将扩展它以查找尚未开始的排队作业。状态无关紧要。
我目前的思路是使用反向嵌套聚合来冒泡所有状态,然后从那里过滤掉我不想要的项目。我也可能会滥用带有 min_doc_count 的术语聚合器来获得我需要的东西。
例子
curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/jobs/" -d'
{
"mappings": {
"event": {
"properties": {
"name": {
"type": "keyword"
},
"status": {
"type": "keyword"
}
}
}
}
}'
- 一些样本数据
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/jobs/_bulk" -d'
{"index":{"_index":"jobs","_type":"event"}}
{"name":"job0", "status":"init"}
{"index":{"_index":"jobs","_type":"event"}}
{"name":"job1", "status":"init"}
{"index":{"_index":"jobs","_type":"event"}}
{"name":"job2", "status":"init"}
{"index":{"_index":"jobs","_type":"event"}}
{"name":"job0", "status":"running"}
{"index":{"_index":"jobs","_type":"event"}}
{"name":"job1", "status":"running"}
{"index":{"_index":"jobs","_type":"event"}}
{"name":"job0", "status":"finished"}
'
- 示例查询
curl -H "Content-Type: application/json" -XGET http://localhost:9200/logs/event/_search -d'
{
"aggs": {
"duplicateNames": {
"terms": {
"field": "name",
"min_doc_count": 2
}
}
}
}' | python -m json.tool
解决方案
所以,说实话!我确实了解上下文和所有内容。但是,我不太明白你的问题。你想在这里实现的目标是什么?
也许在你(做得很好的解释:D)的最后把问题清楚地放在最后。:)
推荐阅读
- javascript - Angular 12 更新让我的字体看起来不一样了
- wikipedia - 如何使用 dbpedia 在维基百科上获取公司的结构化数据?
- maven - 迁移到 java 9 模块时无法使用 maven-jar-plugin 构建可执行 jar
- azure - Azure:无法从 ARM 部署 FortiGate - 错误“不支持提供‘未知’支付工具...”
- vb.net - 使用带有 VB.Net 的 swagger 接收 404 响应
- reactjs - 尝试导入错误:“fade”未从“@material-ui/core/styles”导出
- reactjs - 防止 onClick 事件发生在所有行中,而不是每次单击一行
- jquery - Grunt 和 UglifyJS - 从缩小中排除 jQuery 函数
- c# - System.Net.Security.SslStream 中的 TLS 客户端身份验证支持 - 如何提交可接受的客户端证书 CA 名称?
- c# - PlotModel.InvalidatePlot() 和 PlotView.InvalidatePlot() 之间的区别