ElasticSearch学习

文章40 |   阅读 18961 |   点赞0

来源:https://blog.csdn.net/ywl470812087/category_9621251.html

ElasticSearch bool过滤查询

x33g5p2x  于2021-12-19 转载在 其他  
字(1.0k)|赞(0)|评价(0)|浏览(370)

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

GET /lib5/items/_search 
{ 
  "post_filter": {
    "bool": { 
      "should": [
        {"term": {"price":25}}, 
        {"term": {"itemID": "id100123"}}
      ],
      "must_not": {
        "term":{"price": 30}
      }
    }
  }
}
GET /lib5/items/_search
{
  "query": {
    "bool": {
      "should": [
        {"term": {"price":25}},
        {"term": {"itemID": "id100123"}}
        ],
        "must_not": {
          "term":{"price": 30}
        }
    }
  }
}

范围查询

GET /lib5/items/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "price": {
            "gt": 25,
            "lt": 50
          }
        }
      }
    }
  }
}

是否存在 

GET /lib5/items/_search
{
  "query": {
    "bool": {
      "filter": {
        "exists":{ "field":"price"}
      }
    }
  }
}

相关文章