ElasticSearch
1.es操作
- 01
GET _cat/indices //查看所有索引
2.索引操作(index)
- 01
- 02
- 03
PUT /myindex //创建索引
GET /myindex //查看索引
DELETE /myindex //删除索引
3.文档操作
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
POST /myindex/_doc //添加数据
POST /myindex/_doc/id //数据自定义id
DELETE /myindex/_doc/id // 数据自定义id
//查询
GET /myindex/_doc/id //查询id
GET /myindex/_search //全部数据
GET /myindex/_search //key为value的数据
{
"from": 0,//从第几条开始
"size": 10,//查询多少
"query":{
"match":{
//match 分词匹配查询
//match_all 全量查询
//match_phrase 匹配到一个词
//team 完全匹配
"key":"value"
}
},
"_source": ["name"],//显示多少字段
"sort":{
"name":{
"order" : "desc" //asc
}
}
}
//条件查询
{
"query": {
"bool":{
"must":[
//should 或者or
//must 同时满足and
//must_not 同时不满足
{
"match":{
"key1":"value1"
}
},
{
"match":{
"key2":"value2"
}
}
],
"filter":{//范围查询
"range":{
"age":{
"gt":20//大于20
"gte":20//大于等于20
"eq":30//等于30
"lt":20//小于20
"lt":20//小于20
}
}
}
}
}
}
//聚合查询
{
"aggs":{
"aggsname":{//自定义名称
"team":{
//team分组 avg取平均值
"field":"name"//根据上面类型匹配字段
}
}
},
"size":0//不需要原始数据,只看聚合结果
}
4.mapping
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
GET /myindex/_mapping 获取mapping
PUT /myindex/_mapping 添加mapping
{
"properties":{
"name":{//字段名称
"type":"text",//可以分词查询
"index":true//会被索引并且可以查询
},
"sex":{//字段名称
"type":"keyword",//不分词完整匹配
"index":true//会被索引并且可以查询
},
}
}