jestClient-ES客户端配置

@Configuration
public class InitElasticSearchConfig {

    @Bean
    public JestClient getClientConfig() {
        JestClientFactory factory = new JestClientFactory();
        //集群可以写多个节点,查询的时候不管配置一个还是多个节点,都会到整个集群中去查
        List<String> urlList = Arrays.asList("http://127.0.0.1:9200");
        factory.setHttpClientConfig(new HttpClientConfig
                .Builder(urlList) //参数可以是集群,请先定义一个list集合,将节点url分别添加到list
                //.defaultCredentials("elastic","changeme") //如果使用了x-pack,就要添加用户名和密码
                .gson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'hh:mm:ss").create())
                .multiThreaded(true) //多线程模式
                .connTimeout(60000) //连接超时
                .readTimeout(60000) //由于是基于http,所以超时时间必不可少,不然经常会遇到socket异常:read time out
                .build()); //更多参数请查看api
        JestClient client = factory.getObject();
        return client;
    }

    /**
     * 关闭JestClient客户端
     *
     * @param jestClient
     * @throws Exception
     */
    public void closeJestClient(JestClient jestClient) throws Exception {

        if (jestClient != null) {
            jestClient.close();
        }
    }
}

pom

		<!--ES-->
		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>6.0.0</version>
		</dependency>

		<dependency>
			<groupId>io.searchbox</groupId>
			<artifactId>jest</artifactId>
			<version>6.3.1</version>
		</dependency>
		<!--ES-END-->

关于ES查询在另一篇文章点我查看

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值