没想到我竟然开始分享elasticSearch专题,感慨万分。
由于之前已经分享过elasticSearch的java实现主要方法(如下链接),该文章主要分享使用Kibana对数据的操作。不用通过跑代码的方式,使得某些简单操作更快捷。
elasticSearch的java实现主要方法https://blog.csdn.net/weixin_42311968/article/details/123856299
在开始之前,首先给出我的数据结构mapping,为了简单起见,构建了一个索引名为student1,且type为studentAlias的数据结构,包含两个字段:address和name。同时,有个名称为studentAlias的别名。type和别名可以不一样。(note:以上提到的内容都会在下面有详细的使用说明)
{
"mappings": {
"student": {
"properties": {
"address": {
"type": "keyword"
},
"name": {
"type": "text",
"fields": {
"quanpin": {
"type": "text",
"analyzer": "quanpin_analyzer",
"search_analyzer": "word_analyzer"
},
"substring": {
"type": "text",
"analyzer": "back_edge_ngram_analyzer",
"search_analyzer": "word_analyzer"
}
}
}
}
}
}
}
1.新增
1. 新增一条数据 指定id
PUT 索引名/type/id
PUT student1/studentAlias/1
{
"address":"北京",
"name":"百度"
}
响应: 查询:
2.新增一条数据 不指定id,(随机id类似:AYE4TrsaVlOI6NDwDDvR)
POST 索引名/type
POST student1/studentAlias
{
"name":"微软",
"address":"上海"
}
响应: 查询:
2.删除 1.删除一条数据 指定id
DELETE index名/type名/id
DELETE student1/studentAlias/1
(如果别名唯一的话可以直接通过别名进行删除,不建议,很容易误删数据)
响应:
2.删除一条数据 使用_delete_by_query语句POST 索引名/type/_delete_by_query
POST student1/studentAlias/_delete_by_query
{
"query":{
"term":{
"_id":"1"
}
}
}
响应:
3.修改
同新增逻辑,可以根据key覆盖。等同于JAVA中的MAP,当key值相等时,新value覆盖就value。
4.查询 1.查询数据结构1)查询索引名下所有type中mapping类型的数据结构
GET /别名
GET /studentAlias
2)查询指定type的数据结构
GET /索引名/_mapping/别名
GET /student1/_mapping/studentAlias
2.查询项目数据
1)查询索引名下所有type的所有数据
GET /别名/_search
GET /studentAlias/_search
2)查询指定type下符合条件的数据
GET /索引名/别名/_search
GET /student1/studentAlias/_search
{
"query": {
"match": {
"name": "百度"
}
}
}
还有更多复杂查询,后续补充。。。
2022.06.07



