Elasticsearch索引管理
2016-08-24 09:18
253 查看
1.判断索引是否存在
IndicesExistsResponse indexResponse = ia.client.admin().indices().prepareExists("blog") .execute().actionGet(); System.out.println(indexResponse.isExists());
也可以同时判断多个索引是否存在:
IndicesExistsResponse indexResponse = ia.client.admin().indices().prepareExists("blog","blog1") .execute().actionGet();
2. 判断类型是否存在
TypesExistsResponse typeResponse = ia.client.admin().indices() .prepareTypesExists("news").setTypes("document") .execute().actionGet(); System.out.println(typeResponse.isExists());
3.删除索引
DeleteIndexResponse deleteResponse = ia.client.admin().indices().prepareDelete("news") .execute().actionGet(); if (deleteResponse.isAcknowledged()) { System.out.println("删除索引成功"); } else { System.out.println("删除索引失败"); }
4.创建索引
CreateIndexResponse createIndexResponse = ia.client.admin().indices().prepareCreate("news") .execute().actionGet(); if (createIndexResponse.isAcknowledged()) { System.out.println("创建索引成功"); } else { System.out.println("创建索引失败"); }
5.关闭索引
关闭不使用的索引可以释放节点和集群的资源(比如CPU时钟周期和内存),如果某个索引库不想被搜索也可以直接关闭.关闭索引的RESTful命令:
curl -XPOST "http://127.0.0.1:9200/indexname/_close"
java api:
CloseIndexResponse cIndexResponse = ia.client.admin().indices().prepareClose("indexname ") .execute().actionGet(); if (cIndexResponse.isAcknowledged()) { System.out.println("关闭索引成功"); }
如果要关闭的索引不存在的话会报错.
也可以一次关闭多个索引:
CloseIndexResponse cIndexResponse = ia.client.admin().indices() .prepareClose("indexname1","indexname2") .execute() .actionGet();
6.打开索引
把已经关闭的索引打开。RESTful命令:
curl -XPOST "http://127.0.0.1:9200/indexname/_open"
打开索引的Java api:
OpenIndexResponse oIndexResponse = ia.client.admin().indices() .prepareOpen("indexname1","indexname2") .execute().actionGet(); System.out.println(oIndexResponse.isAcknowledged());
同样,要打开的索引必须是存在的,否则会报IndexNotFoundException.
相关文章推荐
- [Elasticsearch] 索引管理 (四) - 动态映射
- elasticsearch系列三:索引详解(分词器、文档管理、路由详解(集群))
- [Elasticsearch] 索引管理
- [Elasticsearch] 索引管理 (一)
- [Elasticsearch] 索引管理 (三) - 根对象(Root Object)
- [Elasticsearch] 索引管理 (二)
- [Elasticsearch] 索引管理 (一)
- elasticsearch索引管理
- [Elasticsearch] 索引管理 (五) - 默认映射,重索引,索引别名
- ElasticSearch初步学习,管理索引(入门二)
- [Elasticsearch] 索引管理 (五) - 默认映射,重索引,索引别名
- [Elasticsearch] 索引管理 (三) - 根对象(Root Object)
- [Elasticsearch] 索引管理 (四) - 动态映射
- ElasticSearch49:索引管理_快速上机动手实战创建、修改以及删除索引
- Elasticsearch 权威教程 - 索引管理
- elasticsearch 索引 Warmer 管理
- elasticsearch时间格式索引管理工具: curator
- ElasticSearch53:索引管理_定制自己的dynamic mapping策略
- [ElasticSearch2.x]Java API 之 索引管理
- [Elasticsearch] 索引管理 (二)