布尔查询
type | description |
---|---|
must | 必须出现在匹配文档中 |
filter | 必须出现在文档中,但是不打分 |
must_not | 不能出现在文档中 |
should | 应该出现在文档中 |
must
查找名字叫做 james 的球员
POST nba/_search
{
"query": {
"bool":{
"must":[
{
"match":{
"displayNameEn":"james"
}
}
]
}
}
}
filter
POST nba/_search
{
"query": {
"bool":{
"filter":[
{
"match":{
"displayNameEn":"james"
}
}
]
}
}
}
must not
查找 名字叫 james 的球员,但是不在 东部Eastern的 球员
POST nba/_search
{
"query": {
"bool":{
"must":[
{
"match":{
"displayNameEn":"james"
}
}
],
"must_not": [
{
"term":{
"teamConferenceEn": {
"value": "Eastern"
}
}
}
]
}
}
}
should
查找名字叫做 James 的打球时间应该在11到20年西部球员
即使匹配不到也返回,只是评分不同
POST nba/_search
{
"query": {
"bool":{
"must":[
{
"match":{
"displayNameEn":"james"
}
}
],
"must_not": [
{
"term":{
"teamConferenceEn": {
"value": "Eastern"
}
}
}
],
"should": [
{
"range":{
"playYear": {
"gte": 11,
"lte": 20
}
}
}
]
}
}
}
minimum_should_match = 1
代表了最小匹配精度,如果设置了 minimum_should_match=1, 那么should 语句中至少需要有一个条件满足
查出名字叫做James的打球时间在11到20年西部球员
POST nba/_search
{
"query": {
"bool":{
"must":[
{
"match":{
"displayNameEn":"james"
}
}
],
"must_not": [
{
"term":{
"teamConferenceEn": {
"value": "Eastern"
}
}
}
],
"should": [
{
"range":{
"playYear": {
"gte": 11,
"lte": 20
}
}
}
],
"minimum_should_match": 1
}
}
}