2.ES基本操作-索引
Published on: | Views: 81官方文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html
索引操作
1.创建索引:
curl -X PUT "localhost:9200/$INDEX_NAME?pretty"
其中$INDEX_NAME是索引名称,命名需要符合以下规范:
- 只能是小写
- 不能包含 \, /, *, ?, ", <, >, |, (space character), ,, #
- 不能包含 :
- 不能以 - _ + 开头
- 不能是 . 或者 . .
- 不能大于255字节
- 不要以.开头,除非是隐藏或者内部索引
创建时可以指定参数: - 索引配置(settings) - 索引中字段的映射(mappings) - 索引别名(aliases)
示例
curl -X PUT "localhost:9200/user?pretty" -d
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
},
"mappings": {
"properties": {
"name": { "type": "text" }
}
},
"aliases": {
"alias_1": {},
"alias_2": {
"filter": {
"term": { "user.id": "kimchy" }
},
"routing": "shard-1"
}
}
}
number_of_shards:指定分片数量 number_of_replicas:指定副分片数量 properties:指定字段以及格式 aliases: 指定别名
2.查看索引:
curl -X GET "localhost:9200/$INDEX_NAME?pretty"
3.删除索引:
curl -X DELETE "localhost:9200/$INDEX_NAME?pretty"
4.关闭索引
curl -X POST "localhost:9200/$INDEX_NAME/_close?pretty"
5.打开索引
curl -X POST "localhost:9200/$INDEX_NAME/_open?pretty"
6.复制索引
curl -X POST "localhost:9200/$INDEX_NAME/_clone/cloned-$INDEX_NAME?pretty"