|NO.Z.00011|——————————|BigDataEnd|——|Hadoop&ElasticSearch.V11|——|ELK.v11|集群|索引管理|索引操作|
一、索引操作(创建、查看、删除)
### --- 创建索引库语法
~~~ Elasticsearch采用Rest风格API,因此其API就是一次http请求,
~~~ 你可以用任何工具发起http请求
~~~ # 语法
PUT / 索引名称 {
"settings": {
"属性名": "属性值"
}
}
### --- 创建索引库:可以看到索引创建成功了。
~~~ settings:就是索引库设置,其中可以定义索引库的各种属性 比如分片数 副本数等,
~~~ 目前我们可以不设置,都走默认
~~~ # 示例
PUT /yanqi-company-index
PUT /yanqi-employee-index

二、判断索引是否存在
### --- 判断索引是否存在
~~~ # 语法
~~~ HEAD /索引名称
~~~ # 示例
~~~ HEAD /yanqi-company-index

三、查看索引
### --- Get请求可以帮我们查看索引的相关属性信息,格式:查看单个索引
~~~ # 语法
~~~ GET /索引名称
~~~ # 示例
~~~ GET /yanqi-company-index

四、批量查看索引
### --- 批量查看索引
~~~ # 语法
~~~ GET /索引名称1,索引名称2,索引名称3,...
~~~ # 示例
~~~ GET /yanqi-company-index,yanqi-employee-index

五、查看所有索引
### --- 查看所有索引
~~~ # 方式一:GET _all
~~~ # 方式二:GET /_cat/indices?v
~~~ 绿色:索引的所有分片都正常分配。
~~~ 黄色:至少有一个副本没有得到正确的分配。
~~~ 红色:至少有一个主分片没有得到正确的分配。


六、打开索引
### --- 打开索引
~~~ # 语法
~~~ POST /索引名称/_open
~~~ # 示例
~~~ POST /yanqi-company-index/_open

七、关闭索引
### --- 关闭索引
~~~ # 语法
~~~ POST /索引名称/_close
~~~ # 示例
~~~ POST /yanqi-company-index/_close

八、删除索引库:删除索引使用DELETE请求
### --- 删除索引库
### --- 再次查看,返回索引不存在
~~~ # 语法
~~~ DELETE /索引名称1,索引名称2,索引名称3...
~~~ # 示例
~~~ DELETE /yanqi-company-index,yanqi-employee-index


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号