开发者学堂课程【ElasticSearch 最新快速入门教程:布尔值(bool)查询】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/642/detail/10676
布尔值(bool)查询
内容介绍:
一、返回匹配 address=mill&address=lane
二、返回匹配 address=mill or address=lane
三、返回不匹配 address=mill & address=lane
四、返回 age=40 & state! =ID
一、返回匹配 address=mill&address=lane
curl -XPOST’localhost:9200/bank/_search?pretty' -d
‘{
“query":{
"bool":{
“must":{
{"match":{"address":"mill"}},
{“match": {"acdress":"lane"}}
}
}
查询代码:
{
“query":{
"bool":{
“must":{
{
“match": {
"acdress":"mill"
}
},
{
“match": {
"acdress":"lane"
}
}
}
}
}
}
查询结果:
注意:
must:要求所有条件都要满足(类似于&&)
should:任何一个满足就可以(类似||)
must_not:所有条件都不能满足(类似于!(&&))
二、返回匹配 address=mill or address=lane
curl -XPOST’localhost:9200/bank/search?pretty'-d
“{
“query":{
"bool":{
"should": {
{"match":{"address":"mill"}},
{"match":{"address":"lane"}}
}
}
}
}
查询代码:
{
“query":{
"bool":{
“should":{
{
“match": {
"acdress":"mill"
}
},
{
“match": {
"acdress":"lane"
}
}
}
}
}
}
查询结果:
三、返回不匹配 address=mill & address=lane
curl -XPOST’localhost:9200/bank/search?pretty'-d
‘{
“query":{
"bool":{
"must_not": {
{"match":{"address":"mill"}},
{"match":{"address":"lane"}}
}
}
}
}
查询代码:
{
“query":{
"bool":{
“must_not":{
{
“match": {
"acdress":"mill"
}
},
{
“match": {
"acdress":"lane"
}
}
}
}
}
}
查询结果:
四、返回 age=40 & state! =ID
curl-XPOST 'localhost:9200/bank/_search?pretty' -d
{
“query”:{
“bool”:{
“must”:{
{“match”: {“age”:40}}
}
“must_not”:{
{“match”: (“state”:”ID”))
}
}
}
}
查找代码:
{
“query”:{
“bool”:{
“must”:{
“match”: {
“age”:”40”
}
},
“must_not”:{
“match”:{
“state”:”ID”
}
}
}
}
}
查询结果:
注意:
若返回 state=ID,把 must_not 改为 must 即可