通过java代码创建索引库

通过java代码创建索引库_第1张图片

通过java代码创建索引库_第2张图片


    
        org.elasticsearch
        elasticsearch
        5.6.8
    
    
        org.elasticsearch.client
        transport
        5.6.8
    

    
        org.apache.logging.log4j
        log4j-to-slf4j
        2.9.1
    
    
        org.slf4j
        slf4j-api
        1.7.24
    
    
        org.slf4j
        slf4j-simple
        1.7.21
    
    
        junit
        junit
        4.12
    
import org.elasticsearch.client.transport.TransportClient;

  import org.elasticsearch.common.settings.Settings;

  import org.elasticsearch.common.transport.InetSocketTransportAddress;

  import org.elasticsearch.transport.client.PreBuiltTransportClient;

  import org.junit.Test;

  

  import java.net.InetAddress;

  

  public class ESClientTest {

  

    @Test

    public void createIndex() throws Exception{

        Settings settings = Settings.builder()

                .put("cluster.name","my_ES_cluster")

                .build();

  

        TransportClient client = new PreBuiltTransportClient(settings);

        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),9301));

        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),9302));

        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),9303));

  

        client.admin().indices().prepareCreate("index3").get();

  

        client.close();

  

    }

}

通过java代码创建索引库_第3张图片

你可能感兴趣的:(Elasticsearch)