bool查询
- must:必须满足
- filter:必须满足,但执行的是filter上下文,不参与、不影响评分
- should:或
- must_not:必须不满足,在filter上下文中执行,不参与、不影响评分
- minimum_should_match:表示一个文档至少匹配多少个短语才算是匹配成功,一般是在should里面
- disable_coord: 启用和禁用一个文档所包含所有查询关键词的分数得分计算,默认是false
minimum_should_match代表了最小匹配精度,如果设置minimum_should_match=1,那么should 语句中至少需要有一个条件满足, 也可以用百分数表示。
{
"bool": {
"must":[],
"should":[],
"must_not":[],
"filter": [],
}
}
# 必须出现有java, 过滤是用term必须有solr, 价格是必须不是200-300.
# 必须出现shoud的条件个数是1,上面没有出现should肯定查不到, 去掉就能了
POST /book/_search
{
"query": {
"bool": {
"must": {
"match": {
"description": "java"
}
},
"filter": {
"term": {
"name": "solr"
}
},
"must_not": {
"range": {
"price": {
"gte": 200,
"lte": 300
}
}
},
"minimum_should_match": 1,
"boost": 1
}
}
}
空值查询
# 数据准备
POST /test_index/_bulk
{"index": {"_id":"1"}}
{"tags":["search"]}
{"index": {"_id":"2"}}
{"tags":["open_source"]}
{"index": {"_id":"3"}}
{"other_fields":"some data"}
{"index": {"_id":"4"}}
{"tags":null}
{"index": {"_id":"5"}}
{"tags":["search",null]}
# exists就是存在, 如果不存在就用must_not
GET /test_index/_search
{
"query": {
"bool": {
"must": [
{
"exists" : {
"field" : "tags"
}
}
],
"should": [],
"filter": []
}
},
"from": 0,
"size": 10,
"sort": []
}
indices查询
可以在多个索引上进行查询
not_match_query查询其他索引里面的数据