zoukankan      html  css  js  c++  java
  • Es学习第八课, Filter、bool和范围查询

    Filter过滤查询 

    filter是不计算相关性的,同时可以缓存。因此filter速度快于query。

    我们先在kibana上先添加数据来做准备

    POST /lib4/items/_bulk
    { "index": { "_id": 1 }}
    { "price" : 40, "itemID" : "ID1001" }
    { "index": { "_id": 2 }}
    { "price" : 50, "itemID" : "ID1002" }
    { "index": { "_id": 3 }}
    { "price" : 25, "itemID" : "ID1004" }
    { "index": { "_id": 4 }}
    { "price" : 30, "itemID" : "ID1004" }
    { "index": { "_id": 5 }}
    { "price" : null, "itemID" : "ID1005" }

    首先,我们过滤查询价格等于40的文档,如下写法

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

    bool过滤查询

    bool查询可以实现组合过滤查询

    格式:

    {"bool" : {"must":[],"should":[],"must_not":[] } }

    must:必须满足的条件 (相当于and)

    should:可以满足也可以不满足的条件 (相当于or)

    must_not:不需要满足的条件 (相当于not) 

    GET /lib4/items/_search  #满足价格是25或者ID是1004,同时价格不为30
    {
      "query": {
        "bool":{
          "should": [
            {"term":{"price": 25}},
            {"term":{"itemID": "id1004"}}
          ],
          "must_not": [
            {"term":{"price": 30}}
          ]
        }
      }
    }

    范围过滤

    gt:>

    lt:<

    gte:>=

    lte:<=

    GET /lib4/items/_search   #range表示取一定范围的数据
    {
      "query": {
        "bool":{
           "filter": {
             "range": {
               "price": {
                 "gt": 25,
                 "lte": 50
               }
             }
           }
        }
      }
    }
  • 相关阅读:
    SharePoint与RMS集成中关于权限的一个技术点
    SharePoint Alert
    SharePoint Explorer View
    在查看network traffic的时候, TCP Chimney offload的影响
    SharePoint Profile Import
    为SharePoint添加Event Receiver
    通过Telnet来发送邮件
    如何查看扩展出来的web application?
    Windows Host 文件
    Wscript.Shell 对象详细介绍
  • 原文地址:https://www.cnblogs.com/kakatadage/p/9959424.html
Copyright © 2011-2022 走看看