ES6.3自带了sql查询,但是官网上的JDBC连接es6.3文档写的很马虎,本人实现后以作记录,首先安装官网安装ES6.3.
安装后先建立index
PUT /library/book/_bulk?refresh
{"index":{"_id": "Leviathan Wakes"}}
{"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
{"index":{"_id": "Hyperion"}}
{"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
{"index":{"_id": "Dune"}}
{"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
maven依赖
The JDBC driver can be obtained either by downloading it from the elastic.co site or by using a Maven-compatible tool with the following dependency:
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>jdbc</artifactId>
<version>6.3.0</version>
</dependency>
from artifacts.elastic.co/maven
by adding it to the repositories list:
<repositories> <repository> <id>elastic.co</id> <url>https://artifacts.elastic.co/maven</url> </repository> </repositories>
es的jdb jar
https://artifacts.elastic.co/maven/org/elasticsearch/plugin/jdbc/6.3.0/jdbc-6.3.0.jar
es的jdbc jar依赖
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-jdbc-with-dependencies-6.3.0.zip
代码如下
package com.es;
import java.sql.*;
import java.util.Properties;
/**
* Created by Administrator on 2018/6/16 0016.
*/
public class EsSQL {
public static void main(String args[]) throws SQLException {
String driver = "org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver";
try {
Class.forName(driver).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAcces