elasticsearch bool查询

墨蓝 2022-11-19 01:19 286阅读 0赞

bool 查询

must:与关系,相当于关系型数据库中的and。
should:或关系,相当于关系型数据库中的or。
must_not:非关系,相当于关系型数据库中的not。
filter:过滤条件。
range:条件筛选范围。
gt:大于,相当于关系型数据库中的>。
gte:大于等于,相当于关系型数据库中的>=。
lt:小于,相当于关系型数据库中的<。
lte:小于等于,相当于关系型数据库中的<=。

ps

must和filter经常连用, should和filter不常在一起。

filter在bool内.与should和must同级,不要在query里和bool平级,语法错误。

bool嵌套组合

  1. (city = 'New York' AND state = 'NY') AND ((businessName='Java' and businessName='Shop') OR (category='Java' and category = 'Shop'))
  2. {
  3. "query": {
  4. "match_all": { }
  5. },
  6. "filter": {
  7. "bool": {
  8. "must": [
  9. {
  10. "term": {
  11. "city": "New york"
  12. }
  13. },
  14. {
  15. "term": {
  16. "state": "NY"
  17. }
  18. },
  19. {
  20. "bool": {
  21. "should": [
  22. {
  23. "bool": {
  24. "must": [
  25. {
  26. "term": {
  27. "businessName": "Java"
  28. }
  29. },
  30. {
  31. "term": {
  32. "businessName": "Shop"
  33. }
  34. }
  35. ]
  36. }
  37. },
  38. {
  39. "bool": {
  40. "must": [
  41. {
  42. "term": {
  43. "category": "Java"
  44. }
  45. },
  46. {
  47. "term": {
  48. "category": "Shop"
  49. }
  50. }
  51. ]
  52. }
  53. }
  54. ]
  55. }
  56. }
  57. ]
  58. }
  59. }
  60. }

参考链接:

https://www.elastic.co/guide/cn/elasticsearch/guide/current/combining-filters.html

https://www.cnblogs.com/Neeo/articles/10578625.html

http://www.voidcn.com/article/p-yfsxhcpj-bue.html

发表评论

表情:
评论列表 (有 0 条评论,286人围观)

还没有评论,来说两句吧...

相关阅读

    相关 elasticsearch bool查询

    bool 查询 > must:与关系,相当于关系型数据库中的and。 > should:或关系,相当于关系型数据库中的or。 > must\_not:非关系,相当