ES elasticsearch should失效及正確寫法


##預設數據

POST  test/_doc/1
{
"name":"張三",
"sex":"",
"score":70
}
POST  test/_doc/2
{
"name":"李四",
"sex":"",
"score":70
}
POST  test/_doc/3
{
"name":"王五",
"sex":"",
"score":80
}

## 查找 男性並且成績是70或者80的人

ES7之前失效,7之后的版本支持該寫法

GET test/_search
{
"query": {
"bool": {
"must": [
{"term": {
"sex": {
"value":"男"
}
}}
],
"should": [
{"term": {
"score": {
"value": 70
}
}},
{"term": {
"score": {
"value": 80
}
}}
]
}
}
}

 

##第二種寫法

GET test/_search
{
"query": {
"bool": {
"must": [
{"term": {
"sex": {
"value": "男"
}
}},
{
"bool": {
"should": [
{"term": {
"score": {
"value": 70
}
}},
{"term": {
"score": {
"value": 80
}
}}
]
}
}
]

}
}
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM