索引基本操作¶
创建¶
ES 中的索引有一个健康状态 health,有三个状态:
- green: 健康
- yellow: 索引可用,但存在风险
- red: 索引不可用
Warning
ES 默认在创建索引时为索引创建一个备份索引和一个 Primary 索引,可以通过创建时配置
PUT /<INDEX_NAME>
{
"settings": {
"number_of_shards": 1, // 指定主分片的数量
"number_of_replicas": 0 // 指定副本分片的数量
}
}
查看¶
查看所有索引¶
Example
查看的时候带上标题¶
Example
HTTP/1.1 200 OK
content-type: text/plain; charset=UTF-8
content-encoding: gzip
content-length: 193
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open product2 eJAfIwVySY2FXrlCpi2GUg 1 0 0 0 283b 283b
yellow open product1 0bYGE7asQgaxgVqpIDMiCQ 1 1 0 0 283b 283b
查看指定索引¶
查看全部信息:
Example
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-encoding: gzip
content-length: 225
{
"product2": {
"aliases": {},
"mappings": {
"properties": {
"description": {
"type": "text"
},
"title": {
"type": "text"
}
}
},
"settings": {
"index": {
"creation_date": "1657988444815",
"number_of_shards": "1",
"number_of_replicas": "0",
"uuid": "XtoUs9lqQ8eHX8uYaGOonw",
"version": {
"created": "7010199"
},
"provided_name": "product2"
}
}
}
}
查看索引的设置:
Example
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-encoding: gzip
content-length: 180
{
"product2": {
"settings": {
"index": {
"creation_date": "1657988444815",
"number_of_shards": "1",
"number_of_replicas": "0",
"uuid": "XtoUs9lqQ8eHX8uYaGOonw",
"version": {
"created": "7010199"
},
"provided_name": "product2"
}
}
}
}
查看mappings信息:
Example
删除¶
Example
更新¶
ES 中索引只有创建、查看、删除,没有更新操作