最近公司要做后端接口调用,数据存储在es,我的打算是用sql查es,用springboot提供接口调用,es6.3版本开始支持sql查询,好了,废话不多bb,开始咯。
首先先创建一个java项目,pom文件中添加如下依赖:
<repositories>
<repository>
<id>elastic.co</id>
<url>https://artifacts.elastic.co/maven</url>
</repository>
</repositories>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>jdbc</artifactId>
<version>6.3.0</version>
</dependency>
接下来 上代码
import java.sql.*;
import java.util.Properties;
public class EsTest {
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {
String driver = "org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver";
Class.forName(driver).newInstance();
String address = "jdbc:es://127.0.0.1:9200";
Properties connectionProperties = new Properties();
Connection connection = null;
try {
connection = DriverManager.getConnection(address, connectionProperties);
} catch (SQLException e) {
e.printStackTrace();
}
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery("SELECT * FROM flower");
while (results.

本文介绍了如何在Elasticsearch 6.3版本中使用SQL查询,通过JDBC连接ES。首先添加相关依赖,然后解决因需要白金许可证导致的报错问题,通过破解x-pack并替换jar包。接着,获取并修改许可证证书,配置es.yml文件,并将证书发送给ES集群。最后成功实现SQL查询Elasticsearch,计划将其集成到SpringBoot接口中。
最低0.47元/天 解锁文章
5663

被折叠的 条评论
为什么被折叠?



