zoukankan      html  css  js  c++  java
  • 谷粒商城学习——P115-116 es进阶-bool复合查询、filter条件过滤

    bool用来做复合查询

    复合语句可以合并,任何其他查询语句,包括符合语句。这也就意味着,复合语句之间可以互相嵌套

      must:必须所有条件,会贡献相关性得分
      must_not:必须满足所有条件,不会贡献相关性得分,会被当做filter过滤器
      should:应该满足should所列举的条件。满足条件最好,不满足也可以,满足得分更高
      filter:相当于must,不会贡献相关性得分

    GET bank/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "gender": "M"
              }
            },
            {
              "match": {
                "address": "mill"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "age": "18"
              }
            }
          ],
          "should": [
            {
              "match": {
                "lastname": "Wallace"
              }
            }
          ],
          "filter": {
            "range": {
              "age": {
                "gte": 18,
                "lt": 38
              }
            }
          }
        }
      }
    }

    返回结果

    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 3,
          "relation" : "eq"
        },
        "max_score" : 12.585751,
        "hits" : [
          {
            "_index" : "bank",
            "_type" : "account",
            "_id" : "970",
            "_score" : 12.585751,
            "_source" : {
              "account_number" : 970,
              "balance" : 19648,
              "firstname" : "Forbes",
              "lastname" : "Wallace",
              "age" : 28,
              "gender" : "M",
              "address" : "990 Mill Road",
              "employer" : "Pheast",
              "email" : "forbeswallace@pheast.com",
              "city" : "Lopezo",
              "state" : "AK"
            }
          },
          {
            "_index" : "bank",
            "_type" : "account",
            "_id" : "136",
            "_score" : 6.0824604,
            "_source" : {
              "account_number" : 136,
              "balance" : 45801,
              "firstname" : "Winnie",
              "lastname" : "Holland",
              "age" : 38,
              "gender" : "M",
              "address" : "198 Mill Lane",
              "employer" : "Neteria",
              "email" : "winnieholland@neteria.com",
              "city" : "Urie",
              "state" : "IL"
            }
          },
          {
            "_index" : "bank",
            "_type" : "account",
            "_id" : "345",
            "_score" : 6.0824604,
            "_source" : {
              "account_number" : 345,
              "balance" : 9812,
              "firstname" : "Parker",
              "lastname" : "Hines",
              "age" : 38,
              "gender" : "M",
              "address" : "715 Mill Avenue",
              "employer" : "Baluba",
              "email" : "parkerhines@baluba.com",
              "city" : "Blackgum",
              "state" : "KY"
            }
          }
        ]
      }
    }
  • 相关阅读:
    ORACLE 数据迁移到SQL SEVER2005的问题
    sql server性能分析检测数据库阻塞语句
    经典存储过程
    sql server性能分析查询死锁的sql语句
    sql server性能分析索引使用效率评估
    discuz!X2.5不改代码即可去掉网址后面的forum.php后缀
    discuz!X2.5伪静态设置
    详解ListView
    frameset、frame和iframe的区别
    android中的Context到底该怎么用
  • 原文地址:https://www.cnblogs.com/yanan7890/p/15008838.html
Copyright © 2011-2022 走看看