Elasticsearch-sql使用实践

1 - 简介

elasticsearch-sql以插件的形式运行在ES中,拦截_sql开头的请求,将请求中的sql语句解释成es的DSL查询语句,在ES内部调用执行后,将结果返回给用户。

部署后的效果:

curl -XGET -u test_user:test_user "192.168.1.1:9299/_sql" -H 'Content-Type: application/json' -d'select * from agile_subscribe_2_20200526_120400 limit 2'

2 - 安装

下载地址:https://github.com/NLPchina/elasticsearch-sql

版本要与es版本对应

下载好之后,上传到ES服务器,安装

./bin/elasticsearch-plugin install file:/opt/soft/elasticsearch-sql-6.8.0.0.zip

修改ES配置文件,添加http相关参数,用来支持可视化页面。

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

修改好配置文件后,重启ES集群。

3 - 命令行访问

重启ES集群后,命令行即可使用。

curl -XGET -u test_user:test_user "192.168.1.1:9299/_sql" -H 'Content-Type: application/json' -d'select * from indexname limit 2'

4 - 可视化页面

ES 5.x之后,需要安装 node.js 和下载及解压site,然后像这样启动web前端:

cd site-server
npm install express --save
node node-server.js 

然后在Chrome中a
此时,访问[http://site-server:8080/](http://site-server:8080/),即可看到可视化页面。

可视化页面

如果ES启用了xpack认证,那么访问的地址需要更改:

http://site-server:8080/?username=test_user&password=test_user&base_uri=http://192.168.1.1:9299

base_uri是上图中的ES集群地址,username和password是相应的账号、密码。配置好之后,享受在ES上运行SQL的畅快吧。

你可能感兴趣的:(Elasticsearch-sql使用实践)