21-Filter Query过滤查询

除了QueryDSL查询方式,官方还提供了过滤查询



# 过滤查询
GET /products/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": [
        {"terms": {
          "description":[
            "好吃",
            "好用"
          ]
        }}
      ]
    }
  }
}

范围过滤:常用于网站的价格区间搜索

  GET /products/_search
  {
    "query": {
      "bool": {
        "must": [
          {
            "match_all": {}
          }
        ],
        "filter": [
          {"range": {
            "price": {
              "gte": 0,
              "lte": 10000
            }
          }}
        ]
      }
    }
  }

exists fileter:过滤字段,先筛选出有这个字段的数据

      GET /products/_search
      {
        "query": {
          "bool": {
            "must": [
              {
                "match_all": {}
              }
            ],
            "filter": [
              {"exists": {
                "field": "description"
              }}
            ]
          }
        }
      }

ids filter : 索引过滤

      GET /products/_search
      {
        "query": {
          "bool": {
            "must": [
              {
                "match_all": {}
              }
            ],
            "filter": [
              {"ids": {
                "values": [
                  "1","2","3"
                ]
              }}
            ]
          }
        }
      }
posted @ 2022-01-17 23:12  不是孩子了  阅读(56)  评论(0)    收藏  举报