布尔查询
must (查找名字叫做James的球员)
POST /nba/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"displayNameEn": "james"
}
}
]
}
}
}
filter效果同must,但是不打分(查找名字叫做James的球员)
POST /nba/_search
{
"query": {
"bool": {
"filter": [
{
"match": {
"displayNameEn": "james"
}
}
]
}
}
}
must_not不能出现在文档中 (查找名字叫做James,同时teamConferenceEn不能为Eastern 的⻄部球员)
POST /nba/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"displayNameEn": "james"
}
}
],
"must_not": [
{
"term": {
"teamConferenceEn": {
"value": "Eastern"
}
}
}
]
}
}
}
should应该出现在文档中(查找名字叫做James的打球时间应该在11到20年⻄部球员)
可加minimum_should_match参数控制,这里做了两种方案
//--------------------------方案1--------------------------
//即使匹配不到也返回,只是评分不同
POST /nba/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"displayNameEn": "james"
}
}
],
"must_not": [
{
"term": {
"teamConferenceEn": {
"value": "Eastern"
}
}
}
],
"should": [
{
"range": {
"playYear": {
"gte": 11,
"lte": 20
}
}
}
]
}
}
}
//--------------------------方案2--------------------------
//minimum_should_match 最小匹配数,具体怎么用看官网,个人理解的还不透彻
//如果minimum_should_match=1,则变成要查出名字叫做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
}
}
}