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

Java操作ElasticSearch

时间:2019-11-28 21:11:46      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:exception   elastics   catch   dep   utils   port   artifact   版本   enc   

依赖
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.4.1</version>
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.4.1</version>
</dependency>

版本自行选择 注意修改


工具类

package com.util;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;

public class ESUtils {



public static TransportClient getClient(){
try {
TransportClient transportClient = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
return transportClient;
}catch (Exception e){
e.printStackTrace();
}
return null;
}

}




Java操作ElasticSearch

标签:exception   elastics   catch   dep   utils   port   artifact   版本   enc   

原文地址:https://www.cnblogs.com/slAmor/p/11953465.html

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