ElasticSearch 7 搜索(7)范围查询

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

  • 请求
1
localhost:9200/nba/_search
  • 请求体
1
2
3
4
5
6
7
8
9
10
11
12
13
{
// 语义: 查找在nba打了2年到10年以内的球员
"query": {
"range": {
"playYear":{ //playYear 是Long类型 不要写成字符串
"gte": 2,
"lte": 10
}
}
},
"from": 0,
"size": 3
}
  • 响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
"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请求

  • 请求
1
localhost:9200/nba/_search
  • 请求体
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
// 语义: 查找1980年到1999年出生的球员
"query": {
"range": {
"birthDay":{
"gte": "01/01/1980",
"lte": "1999",
"format": "dd/MM/yyyy||yyyy" // 日期格式要对应get lte
}
}
},
"from": 0,
"size": 3
}
  • 响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
"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"
}
}
]
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :