Determine whether the ElasticSearch index Indice and index type exist

The best elasticsearch highlevel java rest api-----bboss

The ClientInterface interface of bboss provides a method for judging whether the ElasticSearch index Indice and index type exist. This article illustrates how to use it.

1. Preparations

Refer to the documentation to import the Elasticsearch client into the project: Integration of Elasticsearch Restful API Case Sharing

2. Determine the existence of codes for ElasticSearch index Indice and index type

//Create es client tool
ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();

//Determine whether the index exists, return true if it exists, and return false if it does not exist
boolean exist = clientUtil.existIndice("twitter");
//Determine whether the index type exists, return true if it exists, and return false if it does not exist
exist = clientUtil.existIndiceType("twitter",//indice
                           "tweet");//type

3. Instance running

It is very simple to determine whether the ElasticSearch index Indice and index type exist. Just integrate the Elasticsearch client into your own project, and then put the above code into the main method or the junit test case to run. The following is the junit test case:

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
	}
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325081273&siteId=291194637