ElasticSearch 7 搜索(7)范围查询

第一种范围查询 GET/POST请求

  • 请求
localhost:9200/nba/_search

  • 请求体
{
  // 语义: 查找在nba打了2年到10年以内的球员 
  "query": {
    "range": {
      "playYear":{ //playYear 是Long类型 不要写成字符串
          "gte": 2,
          "lte": 10
      }
    }
  },
  "from": 0,
  "size": 3
}
  • 响应
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 77,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "United States",
          "teamName" : "热火",
          "birthDay" : 869198400000,
          "country" : "美国",
          "teamCityEn" : "Miami",
          "code" : "bam_adebayo",
          "displayAffiliation" : "Kentucky/United States",
          "displayName" : "巴姆 阿德巴约",
          "schoolType" : "College",
          "teamConference" : "东部",
          "teamConferenceEn" : "Eastern",
          "weight" : "115.7 公斤",
          "teamCity" : "迈阿密",
          "playYear" : 2,
          "jerseyNo" : "13",
          "teamNameEn" : "Heat",
          "draft" : 2017,
          "displayNameEn" : "Bam Adebayo",
          "heightValue" : 2.08,
          "birthDayStr" : "1997-07-18",
          "position" : "中锋-前锋",
          "age" : 22,
          "playerId" : "1628389"
        }
      },
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "9",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "United States",
          "teamName" : "篮网",
          "birthDay" : 893131200000,
          "country" : "美国",
          "teamCityEn" : "Brooklyn",
          "code" : "jarrett_allen",
          "displayAffiliation" : "Texas/United States",
          "displayName" : "贾瑞特 艾伦",
          "schoolType" : "College",
          "teamConference" : "东部",
          "teamConferenceEn" : "Eastern",
          "weight" : "107.5 公斤",
          "teamCity" : "布鲁克林",
          "playYear" : 2,
          "jerseyNo" : "31",
          "teamNameEn" : "Nets",
          "draft" : 2017,
          "displayNameEn" : "Jarrett Allen",
          "heightValue" : 2.11,
          "birthDayStr" : "1998-04-21",
          "position" : "中锋",
          "age" : 21,
          "playerId" : "1628386"
        }
      },
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "United States",
          "teamName" : "尼克斯",
          "birthDay" : 727074000000,
          "country" : "美国",
          "teamCityEn" : "New York",
          "code" : "kadeem_allen",
          "displayAffiliation" : "Arizona/United States",
          "displayName" : "卡迪姆 艾伦",
          "schoolType" : "College",
          "teamConference" : "东部",
          "teamConferenceEn" : "Eastern",
          "weight" : "90.7 公斤",
          "teamCity" : "纽约",
          "playYear" : 2,
          "jerseyNo" : "0",
          "teamNameEn" : "Knicks",
          "draft" : 2017,
          "displayNameEn" : "Kadeem Allen",
          "heightValue" : 1.9,
          "birthDayStr" : "1993-01-15",
          "position" : "后卫",
          "age" : 26,
          "playerId" : "1628443"
        }
      }
    ]
  }
}

第二种范围查询 GET/POST请求

  • 请求
localhost:9200/nba/_search
  • 请求体
{
  // 语义: 查找1980年到1999年出生的球员
  "query": {
    "range": {
      "birthDay":{
          "gte": "01/01/1980",
          "lte": "1999",
          "format": "dd/MM/yyyy||yyyy" // 日期格式要对应get lte
      }
    }
  },
  "from": 0,
  "size": 3
}
  • 响应
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 521,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "United States",
          "teamName" : "老鹰",
          "birthDay" : 831182400000,
          "country" : "美国",
          "teamCityEn" : "Atlanta",
          "code" : "jaylen_adams",
          "displayAffiliation" : "United States",
          "displayName" : "杰伦 亚当斯",
          "schoolType" : "College",
          "teamConference" : "东部",
          "teamConferenceEn" : "Eastern",
          "weight" : "86.2 公斤",
          "teamCity" : "亚特兰大",
          "playYear" : 1,
          "jerseyNo" : "10",
          "teamNameEn" : "Hawks",
          "draft" : 2018,
          "displayNameEn" : "Jaylen Adams",
          "heightValue" : 1.88,
          "birthDayStr" : "1996-05-04",
          "position" : "后卫",
          "age" : 23,
          "playerId" : "1629121"
        }
      },
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "New Zealand",
          "teamName" : "雷霆",
          "birthDay" : 743140800000,
          "country" : "新西兰",
          "teamCityEn" : "Oklahoma City",
          "code" : "steven_adams",
          "displayAffiliation" : "Pittsburgh/New Zealand",
          "displayName" : "斯蒂文 亚当斯",
          "schoolType" : "College",
          "teamConference" : "西部",
          "teamConferenceEn" : "Western",
          "weight" : "120.2 公斤",
          "teamCity" : "俄克拉荷马城",
          "playYear" : 6,
          "jerseyNo" : "12",
          "teamNameEn" : "Thunder",
          "draft" : 2013,
          "displayNameEn" : "Steven Adams",
          "heightValue" : 2.13,
          "birthDayStr" : "1993-07-20",
          "position" : "中锋",
          "age" : 26,
          "playerId" : "203500"
        }
      },
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "United States",
          "teamName" : "热火",
          "birthDay" : 869198400000,
          "country" : "美国",
          "teamCityEn" : "Miami",
          "code" : "bam_adebayo",
          "displayAffiliation" : "Kentucky/United States",
          "displayName" : "巴姆 阿德巴约",
          "schoolType" : "College",
          "teamConference" : "东部",
          "teamConferenceEn" : "Eastern",
          "weight" : "115.7 公斤",
          "teamCity" : "迈阿密",
          "playYear" : 2,
          "jerseyNo" : "13",
          "teamNameEn" : "Heat",
          "draft" : 2017,
          "displayNameEn" : "Bam Adebayo",
          "heightValue" : 2.08,
          "birthDayStr" : "1997-07-18",
          "position" : "中锋-前锋",
          "age" : 22,
          "playerId" : "1628389"
        }
      }
    ]
  }
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/12/elasticsearch-7-search-scope-query/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
ElasticSearch 7 搜索(7)范围查询
第一种范围查询 GET/POST请求 请求 localhost:9200/nba/_search 请求体 { // 语义: 查找在nba打了2年到10年以内的球员 "query": { &q……
<<上一篇
下一篇>>
文章目录
关闭
目 录