我的弹性搜索架构中有 4 个字段。
date
status
type
createdAt
Run Code Online (Sandbox Code Playgroud)
现在,我需要获取所有行
date=today
status = "confirmed"
and where type is not equals to "def"
Run Code Online (Sandbox Code Playgroud)
不过,如果
type=def exists
Run Code Online (Sandbox Code Playgroud)
但仅当该字段createdAt不等于时today。
我当前的查询如下所示:
{
must: [
{ "bool":
{
"must": [
{"term": {"date": 'now/d'}},
{"term": {"status": 'confirmed'}},
]
}
}
],
mustNot: [
{"match": {'createdAt': 'now/d'}},
{"match":{"type": "def"}}
]
}
Run Code Online (Sandbox Code Playgroud)
获取type 不等于“ def”的行。但是,如果某行具有type=def AND createdAT any date but today,则该行不会显示。
我究竟做错了什么?
小智 5
这个查询应该有效。
{
"query": {
"bool": {
"must": [
{ "term": {"date": "now/d" } },
{ "term": {"status": "confirmed" } }
],
"must_not": {
"bool": {
"must": [
{ "match": { "createdAt": "now/d" } },
{ "match": { "type": "def" } }
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我相信您的版本不起作用的原因是 Must_not 中的每个查询都不能匹配。 https://www.elastic.co/guide/en/elasticsearch/guide/current/bool-query.html#_controlling_ precision
所有的must子句都必须匹配,所有的must_not子句都不能匹配,但是有多少个should子句应该匹配呢?默认情况下,不要求任何should 子句匹配,但有一个例外:如果没有must 子句,则至少有一个should 子句必须匹配。
| 归档时间: |
|
| 查看次数: |
9049 次 |
| 最近记录: |