ElasticSearch bool过滤查询

╰半夏微凉° 2023-07-18 06:26 102阅读 0赞

bool过滤查询
可以实现组合过滤查询
格式:
{ “bool”: { “must: 0, “should: O, “must not”:0}}
must:必须满足的条件—-and
should:可以满足也可以不满足的条件—or
must_ not:不需要满足的条件—not

  1. GET /lib5/items/_search
  2. {
  3. "post_filter": {
  4. "bool": {
  5. "should": [
  6. {"term": {"price":25}},
  7. {"term": {"itemID": "id100123"}}
  8. ],
  9. "must_not": {
  10. "term":{"price": 30}
  11. }
  12. }
  13. }
  14. }
  15. GET /lib5/items/_search
  16. {
  17. "query": {
  18. "bool": {
  19. "should": [
  20. {"term": {"price":25}},
  21. {"term": {"itemID": "id100123"}}
  22. ],
  23. "must_not": {
  24. "term":{"price": 30}
  25. }
  26. }
  27. }
  28. }

范围查询

  1. GET /lib5/items/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "filter": {
  6. "range": {
  7. "price": {
  8. "gt": 25,
  9. "lt": 50
  10. }
  11. }
  12. }
  13. }
  14. }
  15. }

是否存在

  1. GET /lib5/items/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "filter": {
  6. "exists":{ "field":"price"}
  7. }
  8. }
  9. }
  10. }

发表评论

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

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

相关阅读

    相关 elasticsearch bool查询

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