es范圍查詢


1.看數據 

POST nba/_search
{
	"query": {
		"ids": {
			"values": [1, 2]
		}
	}
}

  

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "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"
        }
      }
    ]
  }
}

  

2.查找在nba打了2年到10年以內的球員

  這個字段是Long類型

POST /nba/_search
{
  "query": {
    "range": {
      "playYear": {
        "gte": 2,
        "lte": 10
      }
    }
  }
}

  

3.查找1980年到1999年出⽣的球員

  時間的范圍查詢,date類型,是時間戳

POST /nba/_search
{
  "query": {
    "range": {
      "birthDay": {
        "gte": "1999-01-01",
        "lte": "1999-01-09",
        "format": "yyyy-MM-dd"
      }
    }
  }
}

  效果:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "64",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "Lithuania",
          "teamName" : "尼克斯",
          "birthDay" : 915771600000,
          "country" : "立陶宛",
          "teamCityEn" : "New York",
          "code" : "ignas_brazdeikis",
          "displayAffiliation" : "University of Michigan/Lithuania",
          "displayName" : "伊格納斯 布拉茲代基斯",
          "schoolType" : "College",
          "teamConference" : "東部",
          "teamConferenceEn" : "Eastern",
          "weight" : "100.2 公斤",
          "teamCity" : "紐約",
          "playYear" : 0,
          "jerseyNo" : "17",
          "teamNameEn" : "Knicks",
          "draft" : 2019,
          "displayNameEn" : "Ignas Brazdeikis",
          "heightValue" : 2.01,
          "birthDayStr" : "1999-01-08",
          "position" : "前鋒",
          "age" : 20,
          "playerId" : "1629649"
        }
      },
      {
        "_index" : "nba",
        "_type" : "_doc",
        "_id" : "476",
        "_score" : 1.0,
        "_source" : {
          "countryEn" : "United States",
          "teamName" : "騎士",
          "birthDay" : 915426000000,
          "country" : "美國",
          "teamCityEn" : "Cleveland",
          "code" : "collin_sexton",
          "displayAffiliation" : "University of Alabama/United States",
          "displayName" : "科林 塞克斯頓",
          "schoolType" : "College",
          "teamConference" : "東部",
          "teamConferenceEn" : "Eastern",
          "weight" : "86.2 公斤",
          "teamCity" : "克利夫蘭",
          "playYear" : 1,
          "jerseyNo" : "2",
          "teamNameEn" : "Cavaliers",
          "draft" : 2018,
          "displayNameEn" : "Collin Sexton",
          "heightValue" : 1.88,
          "birthDayStr" : "1999-01-04",
          "position" : "后衛",
          "age" : 20,
          "playerId" : "1629012"
        }
      }
    ]
  }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM