码迷,mamicode.com
首页 > 编程语言 > 详细

使用java客户端创建索引库

时间:2020-01-16 21:53:46      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:city   public   一个   tcl   pre   ali   ack   uil   import   

package com.hope.es;

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;

/**
* 创建索引库
* @author newcityman
* @date 2020/1/16 - 18:24
*/
public class ElasticSearchClient {
@Test
public void createIndex() throws Exception{
//1、创建一个setting对象,相当于一个配置信息,主要配置集群的名称
Settings settings = Settings.builder()
.put("cluster.name", "my‐elasticsearch").build();
//2、创建一个客户端client对象
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));
//3、使用client对象,创建一个索引库
client.admin().indices().prepareCreate("index_hello").get();
//4、关闭client对象
client.close();
}
}

使用java客户端创建索引库

标签:city   public   一个   tcl   pre   ali   ack   uil   import   

原文地址:https://www.cnblogs.com/newcityboy/p/12203229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!