packagees;importorg.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;importorg.elasticsearch.client.AdminClient;importorg.elasticsearch.client.IndicesAdminClient;importorg.elasticsearch.client.transport.TransportClient;importorg.elasticsearch.common.settings.Settings;importorg.elasticsearch.common.transport.InetSocketTransportAddress;importorg.elasticsearch.common.xcontent.XContentBuilder;importorg.elasticsearch.common.xcontent.XContentFactory;importorg.elasticsearch.transport.client.PreBuiltTransportClient;importorg.junit.Before;importorg.junit.Test;importjava.io.IOException;importjava.net.InetAddress;importjava.util.HashMap;public classAdminAPI {private TransportClient client = null;//在所有的测试方法之前执行
@Beforepublic void init() throwsException {//设置集群名称
Settings settings = Settings.builder().put("cluster.name", "bigdata").build();//创建client
client = newPreBuiltTransportClient(settings).addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName("192.168.33.100"), 9300),new InetSocketTransportAddress(InetAddress.getByName("192.168.33.101"), 9300),new InetSocketTransportAddress(InetAddress.getByName("192.168.33.102"), 9300));
}//创建索引,并配置一些参数
@Testpublic voidcreateIndexWithSettings() {//获取Admin的API
AdminClient admin =client.admin();//使用Admin API对索引进行操作
IndicesAdminClient indices &