Java操作ElasticSearch
Posted slamor
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java操作ElasticSearch相关的知识,希望对你有一定的参考价值。
依赖
<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的主要内容,如果未能解决你的问题,请参考以下文章