gpt4 book ai didi

elasticsearch - Elasticsearch查询OR和AND函数

转载 作者:行者123 更新时间:2023-12-02 22:37:13 25 4
gpt4 key购买 nike

我是Elasticsearch的新手,正在做一些查询基础知识。

我必须检索那些文档的数量,这些文档是:
包含netflow.src_port ['10','11','12']或netflow.dst_port ['20','21','22']
AND时间戳记在最近15分钟内。

我有一个基本的查询,如下所示:

    body: {
"query": {
"bool":{
"should": [
{"terms": { "netflow.src_port": ["10","11","12"] }},
{"terms": { "netflow.dst_port": ["20","21","22"] }}
],
"must": [
{"range" : {
"@timestamp" : {
"gt" : "now-15m"
}
}}
]
}
}
}

遵循 official documentationshould用于注意:文档不必包含该范围内的src_port或dst_port,但如果包含,则相应地计算成本。

我真正需要的是他们的条件。

如果我的解释不清楚,则下面的内容可能会传达我正在尝试实现的目标:
if( (netflow.src_port contains [10 or 11 or 12] || netflow.dst_port contains [20 or 21 or 22]) && timestamp is within the last 15m.

我到底需要做什么才能获得理想的结果?

最佳答案

尝试更改查询的should部分以包括minimum_should_match属性。例如

{
"bool":{
"should": [
{"terms": { "netflow.src_port": ["10","11","12"] }},
{"terms": { "netflow.dst_port": ["20","21","22"] }}
],
"must": [
{"range" : {
"@timestamp" : {
"gt" : "now-15m"
}
}}
],
"minimum_should_match": 1
}
}

关于elasticsearch - Elasticsearch查询OR和AND函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47287646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com