使用jdbc连接ES6.3

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 (IllegalAccessException e) {
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

非ban必选

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值