Elasticsearch 多条件查询

 

查询 organization_id 为 208 和 event_type 为 007 的数据

复制代码
curl -X GET 10.44.99.102:9200/situation-event/_search?pretty -d 
{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "organization_id": "208"
                }
            }, {
                "term": {
                    "event_type": "007"
                }
            }]
        }
    }
}
复制代码

 

查询 organization_id 为 208 和 event_type 为 007 或者 008 的数据

复制代码
curl -X GET 10.44.99.102:9200/situation-event/_search?pretty -d 
{
    "query": {
        "bool": {
            "must": [{
                "match_phrase": {
                    "organization_id": "208"
                }
            }],
            "should": [{
                    "match_phrase": {
                        "event_type": "007"
                    }
                },
                {
                    "match_phrase": {
                        "event_type": "008"
                    }
                }
            ],
            "minimum_should_match": 1
        }
    }
}
复制代码

 

  

复制代码
 1 curl -X GET 10.44.99.102:9200/situation-event/_search?pretty -d 
 2 {
 3     "query": {
 4         "bool": {
 5             "must": [{
 6                 "term": {
 7                     "organization_id": "208"
 8                 }
 9             }],
10             "should": [{
11                     "terms": {
12                         "event_type": ["007", "008"]
13                     }
14                 }
15             ],
16             "minimum_should_match": 1
17         }
18     }
19 }
多条件查询
复制代码

 

复制代码
{
    "query": {
        "bool": {
            "must": [{
                "range": {
                    "latest_alert_time": {
                        "gte": "2021-06-30 16:34:28",
                        "lt": "2022-06-30 16:34:28"
                    }
                }
            }, {
                "terms": {
                    "severity": ["2", "3"]
                }
            }, {
                "term": {
                    "event_status_cd": "2"
                }
            }, {
                "term": {
                    "alert_status_cd": "4"
                }
            }]
        }
    },
    "aggs": {
        "level": {
            "terms": {
                "field": "severity"
            }
        }
    }
}
多条件时间范围查询并聚合
复制代码

 

复制代码
{
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "latest_alert_time": {
                            "gte": "2021-06-30 16:34:28",
                            "lt": "2022-06-30 16:34:28"
                        }
                    }
                }
            ],
            "must_not": [
                {
                    "regexp": {
                        "alert_seq": "1652108160015861" // 正则
                    }
                }
            ]
        }
    }
}
正则查找
复制代码

 

posted @   你的小可爱吖  阅读(12376)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示