我的 elasticsearch 請求有以下查詢:
{
"query": {
"bool": {
"filter": {
"bool": {
"should" : [
{
"bool" : {
"must_not": {
"exists": {
"field": "visibility_id"
}
}
}
},
{
"bool" : {
"must": {
"terms": {
"visibility.visibility": ["visible"]
}
}
}
}
]
}
}
}
}
}
目標是檢查該行visibility_id是否在表中。如果不是,它將回傳 true 是否達到“must_not”。但如果該visibility_id列存在,則需要檢查它是否設定為“可見”。
目前,如果visibility_id是,它可以作業,null但它不檢查terms. terms可以是其他任何東西,但visible它會起作用。
有人可以幫我嗎,我是彈性搜索的新手。(我嘗試過不使用過濾器 bool,只使用 should 但它也不起作用。)
uj5u.com熱心網友回復:
試試這個查詢,你錯過了minimum_should_match: 1
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must_not": {
"exists": {
"field": "visibility_id"
}
}
}
},
{
"terms": {
"visibility.visibility": [
"visible"
]
}
}
]
}
}
}
如果visibility在nested您的映射中,則您的查詢需要改為:
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must_not": {
"exists": {
"field": "visibility_id"
}
}
}
},
{
"nested": {
"path": "visibility",
"query": {
"terms": {
"visibility.visibility": [
"visible"
]
}
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/459818.html
