作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是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"
}
}}
]
}
}
}
should
用于注意:文档不必包含该范围内的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/
我是一名优秀的程序员,十分优秀!