PUT nba
{
"settings":{
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings":{
"properties":{
"name_cn":{
"type":"text"
},
"name_en":{
"type":"text"
},
"gymnasium":{
"type":"text"
},
"topStar":{
"type":"text"
},
"championship":{
"type":"integer"
},
"date":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss|| yyy-MM-dd||epoch_millis"
}
}
}
}
PUT /nba/_create/1
{
"name_en":"San Antonio Spurs SAS",
"name_cn":"圣安东尼安马刺",
"gymnasium":"AT&T中心球馆",
"championship": 5,
"topStar":"蒂姆·邓肯",
"date":"1995-04-12"
}
PUT /nba/_doc/2
{
"name_en":"Los Angeles Lakers",
"name_cn":"洛杉矶湖人",
"gymnasium":"斯台普斯中心球馆",
"championship": 16,
"topStar":"科比·布莱恩特",
"date":"1947-05-12"
}
PUT /nba/_doc/3
{
"name_en":"Golden State Warriors",
"name_cn":"金州勇士队",
"gymnasium":"甲骨文球馆",
"championship": 6,
"topStar":"斯蒂芬·库里",
"date":"1949-06-13"
}
PUT /nba/_doc/4
{
"name_en":"Miami Heat",
"name_cn":"迈阿密热火队",
"gymnasium":"美国航空球场",
"championship": 3,
"topStar":"勒布朗·詹姆斯",
"date":"1988-06-13"
}
PUT /nba/_doc/5
{
"name_en":"Cleveland Cavaliers",
"name_cn":"克利夫兰骑士队",
"gymnasium":"速贷球馆",
"championship": 1,
"topStar":"勒布朗·詹姆斯5",
"date":"1970-07-13"
}
PUT /nba/_doc/6
{
"name_en":"Cleveland Cavaliers",
"name_cn":"克利夫兰骑士队",
"gymnasium":"速贷球馆",
"championship": 1,
"topStar":"勒布朗·詹姆斯6",
"date":"1970-08-13"
}
PUT /nba/_doc/7
{
"name_en":"Cleveland Cavaliers",
"name_cn":"克利夫兰骑士队",
"gymnasium":"速贷球馆",
"championship": 1,
"topStar":"勒布朗·詹姆斯7",
"date":"1970-09-13"
}
# 查询英文名称为:"Golden State Warriors" 的球队信息
GET /nba/_search
{
"query": {
"match": {
"name_en": "Golden State Warriors"
}
}
}
#2.过滤查询 Filter
#我们让搜索变的复杂一些。我们想要找到当家球星是勒布朗·詹姆斯,但是我们只想得到总冠军多余1次的# 球队。我们的语句将做一些改变用来添加过滤器(filter),它允许我们有效的执行一个结构化搜索
GET /nba/_search
{
"query": {
"bool": {
"filter": {
"range": {
"championship": {
"gte":1
}
}
},
"must": [
{"match": {
"topStar": "勒布朗·詹姆斯"
}}
]
}
}
}
GET nba/_search
## ⽕箭队中按打球时间从⼤到⼩排序的球员
GET nba/_search
{
"query": {
"match": {
"name_cn": "克利夫兰骑士队"
}
},
"sort":[
{
"date":{
"order":"desc"
}
}
]
}
#⽕箭队中按打球时间从⼤到⼩,如果年龄相同则按照身⾼从⾼到低排序的球员
GET nba/_search
{
"query": {
"match": {
"name_cn": "克利夫兰骑士队"
}
},
"sort": [
{
"date": {
"order": "desc"
}
},{
"championship":{
"order": "asc"
}
}
]
}
ElasticSearch(7.2.2)-es之term的多种查询
ElasticSearch 7教程