• es的布尔查询


    1.说明

      

    2.must (查找名字叫做displayAffiliation有Washington的球员)

    POST /nba/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "displayAffiliation": "Washington"
              }
            }
          ]
        }
      }
    }
    

      

    3.filter

      效果同must,但是不打分(查找名字叫做James的球员)

    4.must_not

    POST /nba/_search
    {
      "query": {
        "bool": {
          "must_not": [
            {
              "match": {
                "displayAffiliation": "Washington"
              }
            }
          ]
        }
      }
    }
    

      

    4.should(查找名字叫做James的打球时间应该在11到20年⻄部球员)

      发现should有些问题,有些不是想要的。

    POST /nba/_search
    {
        "query": {
            "bool": {
                "must": [{
                        "match": {
                            "displayNameEn": "james"
                        }
                    }
                ],
                "must_not": [{
                    "term": {
                        "teamConferenceEn": {
                            "value": "Eastern"
                        }
                    }
                }],
                "should": [{
                    "range": {
                        "playYear": {
                            "gte": 11,
                            "lte": 20
                        }
                    }
                }]
            }
        }
    }

      效果:

    {
      "took" : 1,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 3,
          "relation" : "eq"
        },
        "max_score" : 5.699642,
        "hits" : [
          {
            "_index" : "nba",
            "_type" : "_doc",
            "_id" : "267",
            "_score" : 5.699642,
            "_source" : {
              "countryEn" : "United States",
              "teamName" : "湖人",
              "birthDay" : 473230800000,
              "country" : "美国",
              "teamCityEn" : "Los Angeles",
              "code" : "lebron_james",
              "displayAffiliation" : "No College/United States",
              "displayName" : "勒布朗 詹姆斯",
              "schoolType" : "High School",
              "teamConference" : "西部",
              "teamConferenceEn" : "Western",
              "weight" : "113.4 公斤",
              "teamCity" : "洛杉矶",
              "playYear" : 16,
              "jerseyNo" : "23",
              "teamNameEn" : "Lakers",
              "draft" : 2003,
              "displayNameEn" : "LeBron James",
              "heightValue" : 2.03,
              "birthDayStr" : "1984-12-30",
              "position" : "前锋",
              "age" : 35,
              "playerId" : "2544"
            }
          },
          {
            "_index" : "nba",
            "_type" : "_doc",
            "_id" : "214",
            "_score" : 4.699642,
            "_source" : {
              "countryEn" : "United States",
              "teamName" : "火箭",
              "birthDay" : 620107200000,
              "country" : "美国",
              "teamCityEn" : "Houston",
              "code" : "james_harden",
              "displayAffiliation" : "Arizona State/United States",
              "displayName" : "詹姆斯 哈登",
              "schoolType" : "College",
              "teamConference" : "西部",
              "teamConferenceEn" : "Western",
              "weight" : "99.8 公斤",
              "teamCity" : "休斯顿",
              "playYear" : 10,
              "jerseyNo" : "13",
              "teamNameEn" : "Rockets",
              "draft" : 2009,
              "displayNameEn" : "James Harden",
              "heightValue" : 1.96,
              "birthDayStr" : "1989-08-26",
              "position" : "后卫",
              "age" : 30,
              "playerId" : "201935"
            }
          },
          {
            "_index" : "nba",
            "_type" : "_doc",
            "_id" : "266",
            "_score" : 4.699642,
            "_source" : {
              "countryEn" : "United States",
              "teamName" : "国王",
              "birthDay" : 854082000000,
              "country" : "美国",
              "teamCityEn" : "Sacramento",
              "code" : "justin_james",
              "displayAffiliation" : "United States",
              "displayName" : "贾斯汀 詹姆斯",
              "schoolType" : "College",
              "teamConference" : "西部",
              "teamConferenceEn" : "Western",
              "weight" : "86.2 公斤",
              "teamCity" : "萨克拉门托",
              "playYear" : 0,
              "jerseyNo" : "",
              "teamNameEn" : "Kings",
              "draft" : 2019,
              "displayNameEn" : "Justin James",
              "heightValue" : 2.01,
              "birthDayStr" : "1997-01-24",
              "position" : "后卫-前锋",
              "age" : 22,
              "playerId" : "1629713"
            }
          }
        ]
      }
    }
    

      

    5.提高精度

      "minimum_should_match": 1,表示至少有一个条件需要满足

    POST /nba/_search
    {
        "query": {
            "bool": {
                "must": [{
                        "match": {
                            "displayNameEn": "james"
                        }
                    }
                ],
                "must_not": [{
                    "term": {
                        "teamConferenceEn": {
                            "value": "Eastern"
                        }
                    }
                }],
                "should": [{
                    "range": {
                        "playYear": {
                            "gte": 11,
                            "lte": 20
                        }
                    }
                }],
                "minimum_should_match": 1
            }
        }
    }

      效果:

    {
      "took" : 11,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 5.699642,
        "hits" : [
          {
            "_index" : "nba",
            "_type" : "_doc",
            "_id" : "267",
            "_score" : 5.699642,
            "_source" : {
              "countryEn" : "United States",
              "teamName" : "湖人",
              "birthDay" : 473230800000,
              "country" : "美国",
              "teamCityEn" : "Los Angeles",
              "code" : "lebron_james",
              "displayAffiliation" : "No College/United States",
              "displayName" : "勒布朗 詹姆斯",
              "schoolType" : "High School",
              "teamConference" : "西部",
              "teamConferenceEn" : "Western",
              "weight" : "113.4 公斤",
              "teamCity" : "洛杉矶",
              "playYear" : 16,
              "jerseyNo" : "23",
              "teamNameEn" : "Lakers",
              "draft" : 2003,
              "displayNameEn" : "LeBron James",
              "heightValue" : 2.03,
              "birthDayStr" : "1984-12-30",
              "position" : "前锋",
              "age" : 35,
              "playerId" : "2544"
            }
          }
        ]
      }
    }
    

      

  • 相关阅读:
    Spark 1.1.0 安装测试 (分布式 Yarn-cluster模式)
    HBase Mac OSX 安装笔记
    hbase centOS生产环境配置笔记 (1 NameNode, 1 ResourceManager, 3 DataNode)
    ssh 配置自动登录
    CentOS 修改线程数限制等(limits.conf)
    Hadoop Mac OSX 安装笔记
    centos7安装及部署zabbix监控
    设置linux中Tab键的宽度(可永久设置)
    基于NFS共享存储实现KVM虚拟机动态迁移
    KVM虚拟化平台环境部署
  • 原文地址:https://www.cnblogs.com/juncaoit/p/12717026.html
Copyright © 2020-2023  润新知