elasticsearch Filter查询bool查询

filter是不计算相关性的,同时可以cache,因此filter速度要快与query

GET /lib4/items/_search
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "price": "40"
        }
      }
    }
  }
}

GET /lib4/items/_search
{
  "query": {
    "bool": {
      "filter": {
        "terms": {
          "price": [25,40]
        }
      }
    }
  }
}

GET /lib4/items/_search
{
  "query": {
    "bool": {
      "filter": {"term": {
        "itenID": "id100123"    //由于前面用的事动态映射,itenId默认是分词的,系统会自动把ID100123变成小写
      }}
    }
  }
}

bool过滤查询

  可以实现组合查询,格式{"bool":{"must":[],"should":[],"must_not":[]}}

must:必须满足的条件---and

should:可以满足也可以不满足的条件 --or

must_not:不需要满足的条件---not

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

范围过滤

gt >         lt <             gte>=     lte<=

过滤非空

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

 

你可能感兴趣的:(elasticsearch)