Pom文件配置
依赖版本号对应elasticsearch的版本
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.6.3</version>
</dependency>
<!-- 官网只有客户端依赖配置,需要加上下面的elasticsearch依赖 -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.6.3</version>
</dependency>
还需要依赖log4j
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
查询示例
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("ip地址"), 端口号));
GetResponse response = client.prepareGet(index, type, id).get();//根据index,type,id获取相应数据
Map<String, Object> map = response.getSource();//获取response中的返回数据
client.close();
更多api可查看官方文档