文章目录
操作es
1. 创建一个索引
http://localhost:9200/索引名称 //请求类型为put
http://localhost:9200/_cat/indices?v //_cat表示查看的意思 indeices表示所有索引,请求方法为get ?v的意思是返回字段头名称
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open test O00HZXiWSZ-55XZwkLMkww 1 1 0 0 208b 208b
yellow open shopping IMBWH0f_Sym9Laeby6ACMA 1 1 0 0 208b 208b
- health:表示服务器健康状况:green(集群完整),yellow(单点正常、集群不完整)、red(单点不正常)
- status:open(打开)、关闭
- index: 索引名
- uuid:索引统一编号
- pri:主分片数量
- rep:副本数量
- docs.count:可用文档数量
- doccs.deleted 文档删除状态(逻辑删除)
- store.size 主分片和副分片整体占空间大小
- pri.store.size 主分片占空间大小
2. 获取索引的信息
http://localhost:9200/test # 请求方法为get,获取单个索引的信息
{
"test": {//索引名
"aliases": {},//别名
"mappings": {},//映射
"settings": {//设置
"index": {//设置 - 索引
"creation_date": "1617861426847",//设置 - 索引 - 创建时间
"number_of_shards": "1",//设置 - 索引 - 主分片数量
"number_of_replicas": "1",//设置 - 索引 - 副本数量
"uuid": "J0WlEhh4R7aDrfIc3AkwWQ",//设置 - 索引 - 统一编号
"version": {//版本
"created": "7080099"
},
"provided_name": "test"//设置 - 索引 - 名字
}
}
}
}
3. 删除索引
#删除索引
http://localhost:9200/test #请求方法为delete
4. 添加文档
索引创建好之后,接下来创建文档,并添加数据。
#请求地址,请求方法为post
http://localhost:9200/test/_doc
#传递内容必须为json样式
{
"title":"小米手机",
"category":"小米",
"images":"http://www.xiaomi.com",
"prices":399.00
}
# 返回数据样式
{
"_index": "test", //索引名
"_type": "_doc",//类型-文档
"_id": "ErVnXoIBbx01rSqPeraY",//唯一标识,类比与mysql中的主键
"_version": 1,//版本
"result": "created",//结果,这里表示创建
"_shards": {
"total": 2,//分片总数
"successful": 1,//1为成功
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
# 可以指定_id,唯一标识
http://localhost:9200/test/_doc/1
如果需要增加数据时明确数据主键,那么请求方式也可以为put。