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