bool查询

  • must:必须满足
  • filter:必须满足,但执行的是filter上下文,不参与、不影响评分
  • should:或
  • must_not:必须不满足,在filter上下文中执行,不参与、不影响评分
  • minimum_should_match:表示一个文档至少匹配多少个短语才算是匹配成功,一般是在should里面
  • disable_coord: 启用和禁用一个文档所包含所有查询关键词的分数得分计算,默认是false

minimum_should_match代表了最小匹配精度,如果设置minimum_should_match=1,那么should 语句中至少需要有一个条件满足, 也可以用百分数表示。

  1. {
  2. "bool": {
  3. "must":[],
  4. "should":[],
  5. "must_not":[],
  6. "filter": [],
  7. }
  8. }
  1. # 必须出现有java, 过滤是用term必须有solr, 价格是必须不是200-300.
  2. # 必须出现shoud的条件个数是1,上面没有出现should肯定查不到, 去掉就能了
  3. POST /book/_search
  4. {
  5. "query": {
  6. "bool": {
  7. "must": {
  8. "match": {
  9. "description": "java"
  10. }
  11. },
  12. "filter": {
  13. "term": {
  14. "name": "solr"
  15. }
  16. },
  17. "must_not": {
  18. "range": {
  19. "price": {
  20. "gte": 200,
  21. "lte": 300
  22. }
  23. }
  24. },
  25. "minimum_should_match": 1,
  26. "boost": 1
  27. }
  28. }
  29. }

空值查询

  1. # 数据准备
  2. POST /test_index/_bulk
  3. {"index": {"_id":"1"}}
  4. {"tags":["search"]}
  5. {"index": {"_id":"2"}}
  6. {"tags":["open_source"]}
  7. {"index": {"_id":"3"}}
  8. {"other_fields":"some data"}
  9. {"index": {"_id":"4"}}
  10. {"tags":null}
  11. {"index": {"_id":"5"}}
  12. {"tags":["search",null]}
  13. # exists就是存在, 如果不存在就用must_not
  14. GET /test_index/_search
  15. {
  16. "query": {
  17. "bool": {
  18. "must": [
  19. {
  20. "exists" : {
  21. "field" : "tags"
  22. }
  23. }
  24. ],
  25. "should": [],
  26. "filter": []
  27. }
  28. },
  29. "from": 0,
  30. "size": 10,
  31. "sort": []
  32. }

indices查询

可以在多个索引上进行查询

not_match_query查询其他索引里面的数据