ES HEAD常用操作
ES以RESTFul风格来命名API的,其API的基本格式如下:
http://<ip>:<port>/<索引>/<类型>/<文档编号>
1. 进入HEAD界面
Web UI:http://192.168.0.99:9100
2. 创建索引库
索引受文件系统的限制。仅可能为小写字母,不能下划线开头。同时需遵守下列规则:
- 不能包括 , /, *, ?, “, <, >, |, 空格, 逗号, #
- 7.0版本之前可以使用冒号:,但不建议使用并在7.0版本之后不再支持
- 不能以这些字符 -, _, + 开头
- 不能包括 . 或 …
- 长度不能超过 255 个字符
1. 页面指引创建
依次进入“索引” -> “新建索引”,填写“索引名称”、“分片数”、“副本数”,点击确认即可。
2. Rest API创建
1. 简单创建语句
PUT <索引名> // 格式PUT test{}
2. 创建映射
URL:http://localhost:9200/test/PUT _mappings{"properties": {"cnName": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"emp_name": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"mark": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"emp_id": {"type": "text","fields": {"keyword": {"type": "keyword"}}}}}
3. 创建带映射的索引
URL:http://localhost:9200PUT test{"settings": {"index": {"number_of_shards": "1","number_of_replicas": "1"}},"mappings": {"properties": {"cnName": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"emp_name": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"mark": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"emp_id": {"type": "text","fields": {"keyword": {"type": "keyword"}}}}}}
4. 创建自定义Type类型的索引
创建简单索引。
URL:http://ltsr003:9200PUT test
设置Type类型。
URL:http://ltsr003:9200/test/_mapping/info/PUT ?include_type_name=true{"properties":{"name23": {"type": "keyword"}}}
3. 新增数据
1. 指定ID
PUT /[index]/[type]/[id] // 格式PUT /user/mock/1{"name": "zhangsan","country": "China","age": 18,"date": "2019-05-31"}
2. 自动生成ID
POST /[index]/[type] // 格式POST /user/mock{"name": "zhangsan2","country": "China","age": 18,"date": "2019-05-31"}
4. 查询数据
1. 查询所有数据
GET /_search{}
2. 查看指定索引库和类型所有数据
GET /[index]/[type]/_search // 格式GET /user/mock/_search{}
3. 根据ID搜索
GET /[index]/[type]/[id] // 格式GET /user/mock/1{}
5. 新增数据
URL:http://localhost:9200POST test/_doc{"cnName": "李四","emp_name": "lisi","mark": "lisi","emp_id": "002"}
6. 更新数据
1. doc修改
POST /[index]/[type]/[id]/_update // 格式POST /user/mock/1/_update{"doc": {"name": "修改内容TEST...."}}
2. scripts修改
POST /[index]/[type]/[id]/_update // 格式POST /user/mock/1/_update{"script": {"lang": "painless","inline": "ctx._source.age += 20"}}
7. 删除数据
DELETE /[index]/[type]/[id] // 格式DELETE /user/mock/1{}
8.删除索引
1. 页面指引删除
依次进入“概览” -> “<待删除的索引>” -> “动作” -> “删除”,输入“删除”,点击确认即可。
2. Rest API删除
修改URL栏:
http://192.168.0.99:9200/user
之后:
DELETE{}
参考
博客园:【ES】Head插件操作ElasticSearch增删改查
https://www.cnblogs.com/zhaixingzhu/p/12562834.html
