ElasticSearch基本操作
1.创建索引(PUT)
http://127.0.0.1:9200/my_index
2.获取指定索引(GET)
http://127.0.0.1:9200/my_index
3.获取全部索引(GET)
http://127.0.0.1:9200/_cat/indices?v
4.删除索引(delete)
http://127.0.0.1:9200/my_index
5.创建文档(post)【自定义id】
http://127.0.0.1:9200/my_index/_doc/1001
{
"name":"张三",
"age":20
}
6.查询 -- 主键查询 &全查询 (get)
http://127.0.0.1:9200/my_index/_doc/1001
http://127.0.0.1:9200/my_index/_search
7.全量修改(put)&局部修改(post)
http://127.0.0.1:9200/my_index/_doc/1001
{ "name":"小刘", "age":25 } http://127.0.0.1:9200/my_index/_update/1001 { "doc":{ "name":"李四" } }8.删除(delete)
http://127.0.0.1:9200/my_index/_doc/1001
9.条件查询&分页查询&查询排序
http://127.0.0.1:9200/my_index/_search
{ "query":{ "match":{ "name":"李四" //指定条件查询 } } } { "query":{ "match_all":{ //查全部 } }, "from":0, //当前页 "size":5, //页码 "_source":["name"], //指定查询字段 "sort":{ "age":{ "order":"desc" } } }10.多条件查询&范围查询
http://127.0.0.1:9200/my_index/_search { "query":{ "bool":{ "must":[ //类似and "should":[ //类似or { "match":{ "name":"李四" } }, { "match":{ "age":"25" } } ], "filter":{ //过滤 "ranger":{ //范围 "age" : { //年龄字段 "gt" : 20 //大于20 } } } } } }11.全文检索&完全匹配&高亮查询
http://127.0.0.1:9200/my_index/_search
{ "query":{ "match_phrase":{ //完全匹配 "match":{ //模糊匹配 "name":"李四" } }, "highlight":{ "fields":{ "name":{} //高亮字段 } } }12.聚合查询
http://127.0.0.1:9200/my_index/_search
{ "aggs":{ //聚合操作 "age_group":{ //自定义名称 "terms": { //分组 "field":"age" //分组字段 } }, "age_avg":{ //自定义名称 "avg": { //平均值 "field":"age" //分组字段 } } }, "size":0 //只显示统计结果,不看原始数据 }13.映射关系
http://127.0.0.1:9200/my_index/_mapping
{ "properties":{ "name" : { "type" : "text", //表示可以分词查询 "index" : true //表示可以索引查询 }, "age" : { "type" : "keyword", //表示完全匹配 "index" : false // 表示不能被索引 不能按这个字段查询 } } }