elasticsearch 数据库 Elasticsearch-sql 插件的安装和启动以及JDBC访问elasticsearch

我安装的elasticsearch版本是elasticsearch-6.2.3,6.3版本之后,elasticsearch内置集成了x-pack插件,只能使用部分功能,需要使用全部功能需要授权的,而通过SQL访问elasticsearch需要授权的部分(收费的),但是有大神已经破解了。

插件地址

https://github.com/NLPchina/elasticsearch-sql

安装步骤:

1.下载elasticsearch-sql zip包,直接下载到es根目录的plugin的目录下,要下载对应的elasticsearch对应的 Elasticsearch-sql插件版本,如果不知道可以在 Elasticsearch-sql官网查看,地址是:https://github.com/NLPchina/elasticsearch-sql

./bin/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/6.2.3.0/elasticsearch-sql-6.2.3.0.zip

2. 5.0以上版本还需要下载: wget https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip,这个es-sql-site-standalone.zip没有版本之分,统一下载这个。

3.解压:unzip es-sql-site-standalone.zip d

到site-server目录下,cd site-server

执行,npm install express --save

4.启动,node node-server.js,

5.默认启动是以8080端口启动的,需要修改端口号的在site_configuration.json配置文件中修改

cd es-sql-site/site-server vim site_configuration.json

注意:es-sql 5.x版本以后需要node及npm的安装,可以通过node -v和npm -v 命令查看是否安装的npm和node

启动后访问遇到的问题:

启动后的通过IP+配置的端口访问web页面

1.遇到以下的问题,是因为访问elasticsearch的地址可端口不对导致的,


 Error:"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /_sql</pre>\n</body>\n</html>\n"

在页面的右上角修改IP和端口:

2.遇到一下问题需要修改elasticsearch配置文件,添加cors:

http.cors.enabled: true
http.cors.allow-credentials: true
http.cors.allow-origin: "/.*/"
http.cors.allow-headers: WWW-Authenticate,X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization

 通过JDBC访问elasticsearch

elasticsearch安装完elasticsearch-SQL插件后,可以通过java中JDBC访问elasticsearch,直接写SQL语句可以查询es数据库

直接上代码:

依赖有: 

注意,这个elasticsearch-sql底层是通过Druid实现的,elasticsearch-sql这个jar中的Druid的版本是1.0.15,如果你的项目中有引用其他版本的Druid包,有可能出现冲突,最好保持在1.0.15。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值