[英]ElasticSearch query with filter or bool
我有3個字段,例如field1
, field2
和field3
。 我需要創建這樣的東西:
if { field1 != 1 AND field2 != 1 AND field3 != 1 } OR if { field1 != 2 AND field2 != 2 AND field3 != 2 }
我試圖通過兩個bool
query
來做到這一點,但沒有任何回報。 然后,我嘗試將這些查詢包裝到一個filter
,但總是拋出異常, no query defined for [filter]]
。 但是我對這個過濾器的bool
query
始終是空的,它什么也沒有返回。 我可以在bool
query
添加一些內容以檢索所有結果,然后對其進行過濾嗎? 還是我需要以其他方式創建查詢,但是如何?
這是你怎么做
{
"query": {
"filtered": {
"filter": {
"or": [
{
"and": [
{
"not": {
"term": {
"field1": "1"
}
}
},
{
"not": {
"term": {
"field2": "1"
}
}
},
{
"not": {
"term": {
"field3": "1"
}
}
}
]
},
{
"and": [
{
"not": {
"term": {
"field1": "2"
}
}
},
{
"not": {
"term": {
"field2": "2"
}
}
},
{
"not": {
"term": {
"field3": "2"
}
}
}
]
}
]
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.