1. 使用说明网址
- https://opendistro.github.io/for-elasticsearch-docs/docs/sql/workbench/
- https://github.com/opendistro-for-elasticsearch/sql/blob/main/sql-jdbc/CONTRIBUTING.md
2. 环境
- 环境 jdk11
- elasticsearch: elasticsearch-7.10.2
3. 服务端Elasticsearch plugin opendistro-sql插件安装
wget https://d3g5vo6xdbdb9a.cloudfront.net/downloads/elasticsearch-plugins/opendistro-sql/opendistro-sql-1.13.0.0.zip
bin/elasticsearch-plugin install file:///opt/elk7/opendistro-sql-1.13.0.0.zip
bin/elasticsearch-plugin install https://d3g5vo6xdbdb9a.cloudfront.net/downloads/elasticsearch-plugins/opendistro-sql/opendistro-sql-1.13.0.0.zip
4. 客户端开发
<dependency>
<groupId>com.amazon.opendistroforelasticsearch.client</groupId>
<artifactId>opendistro-sql-jdbc</artifactId>
<version>1.13.0.0</version>
</dependency>
@Test
public void testOpendistroSql() throws Exception {
Properties connectionProperties = new Properties();
String address = "jdbc:elasticsearch://192.168.6.136:9200";
try {
Connection connection = DriverManager.getConnection(address, connectionProperties);
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery(
"SELECT * FROM hotel ORDER BY city DESC LIMIT 5");
while(results.next()){
System.out.println(results.getString("hotelName"));
System.out.println(results.getString("label"));
}
}catch (Exception e){
e.printStackTrace();
}
}