您现在的位置是:首页 > 文章详情

判断ElasticSearch索引Indice和索引类型是否存在

日期:2018-05-04点击:382
The best elasticsearch highlevel java rest api-----bboss

在bboss的ClientInterface 接口提供了判断ElasticSearch索引Indice和索引类型是否存在的方法,本文举例说明其使用方法。

1.准备工作
参考文档在项目中导入Elasticsearch客户端: 集成Elasticsearch Restful API案例分享

2.判断ElasticSearch索引Indice和索引类型存在
//创建es客户端工具 ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); //判读索引是否存在,存在返回true,不存在返回false boolean exist = clientUtil.existIndice("twitter"); //判断索引类型是否存在,存在返回true,不存在返回false exist = clientUtil.existIndiceType("twitter",//indice "tweet");//type

3.实例运行
判断ElasticSearch索引Indice和索引类型是否存在非常简单,只要将Elasticsearch客户端集成到自己的项目中,然后将上述代码放入main方法或者junit测试用例中运行即可,以下是junit测试用例:
package org.bboss.eshelloword; import org.frameworkset.elasticsearch.ElasticSearchHelper; import org.frameworkset.elasticsearch.client.ClientInterface; import org.junit.Test; public class IndiceExistTest { @Test public void testExist(){ //创建es客户端工具 ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); //判读索引是否存在,存在返回true,不存在返回false boolean exist = clientUtil.existIndice("twitter"); //判断索引类型是否存在,存在返回true,不存在返回false exist = clientUtil.existIndiceType("twitter",//indice "tweet");//type } }

5 开发交流
elasticsearch技术交流群:166471282

elasticsearch微信公众号:bbossgroups
img_a21db47cf20ac4820026d60bcb2b9470.jpe
原文链接:https://yq.aliyun.com/articles/621741
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章