- 所需环境
- 安装并成功运行elasticsearch
- 下载postman
- 创建索引
- PUT请求
http://IP地址:端口/索引名称
- 查看单个索引信息
- GET请求
http://IP地址:端口号/索引名称
- 返回结果
{
"xiemaoshu": { // 索引名称
"aliases": {},
"mappings": {},
"settings": { // 设置
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "xiemaoshu",
"creation_date": "1621758118555",
"number_of_replicas": "1",
"uuid": "5mUtFPlTRCSZG6r-sPrkYw",
"version": {
"created": "7100099"
}
}
}
}
}
- 查看所有索引列表
- GET请求
http://IP地址:端口号/_cat/indices?v
- 删除索引
- DELETE请求
http://IP地址:端口/索引名称
- 添加数据(也就是索引下的文档)
- 使用postman将数据内容,填写在body中,body的格式要选择"raw"
- POST请求
http://IP地址:端口号/索引名称/_doc
-
红圈部分泪腺要选择正确,否者会报错
-
添加数据并指定ID
-
ES默认会生成随机ID,如果想添加数据时指定ID,可以在请求路径上写明
- POST请求
http://IP地址:端口号/索引名称/_doc/ID值
- 查看数据(文档)
- 可以使用唯一ID查看单条数据信息
- GET请求
http://IP地址:端口号/索引名称/_doc/ID
- 查询索引下所有数据
- GET请求
http://IP地址:端口号/索引名称/_search
- 返回结果说明
{
"took": 140,// 总耗时(毫秒)
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": { // 命中结果
"total": {
"value": 2,// 合计数
"relation": "eq"
},
"max_score": 1.0,
"hits": [ // 命中数据
{
"_index": "xiemaoshu",
"_type": "_doc",
"_id": "m5V0mHkBAtMPfMQ4h4Hl",
"_score": 1.0,
"_source": {
"name": "xms",
"age": 24,
"sex": "男"
}
},
{
"_index": "xiemaoshu",
"_type": "_doc",
"_id": "1001",
"_score": 1.0,
"_source": {
"name": "xms1001",
"age": 24,
"sex": "男"
}
}
]
}
}
- 修改文档
- 指定文档ID,将新的数据放在body中发送,进行全量修改
- POST请求
http://IP地址:端口/索引名称/ID
- 修改文档中某个字段
- POST请求
http://IP地址:端口/索引名称/_update/文档ID
- 删除文档
- DELETE请求
http://IP地址:端口号/索引名称/_doc/文档ID