es-sql

安装es-sql 插件

  1. 下载插件安装包,找到es对应版本的安装包
 wget https://github.com/NLPchina/elasticsearch-sql/releases/download/6.2.4.0/elasticsearch-sql-6.2.4.0.zip
  1. 将安装包解压,放到es安装路径下的plugins目录下
# 如果已经安装了其他插件需要,新建一个目录,然后把zip包拷贝到新建的目录下解压
cd {es_home}/elasticsearch-6.2.4/plugins/

mkdir elasticsearch

mv {sqlzip_home}/elasticsearch-sql-6.2.4.0.zip .

unzip elasticsearch-sql-6.2.4.0.zip

mv elasticsearch/* .

  1. 修改es配置文件,支持跨域
cd {es_home}/elasticsearch-6.2.4/config

vi elasticsearch.yml

# 添加
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: "GET,POST"
http.cors.allow-credentials: true

  1. 重启es服务
./elasticsearch -d

安装es-sql 可是化工具

准备工作,需要安装node.js,修改es配置文件,支持跨域操作

1.下载安装文件
下载地址

wget https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip

2.解压

unzip es-sql-site-standalone.zip 

解压后悔生成两个文件夹, _site和site-server

3.编译

 cd site-server/
  npm install express --save
  
# 修改端口号,默认是8080
vi site_configuration.json

4. 后台启动

nohup node node-server.js &

5.访问
访问地址

在版本号后面添加es的http访问地址
http://ip:port/

es-sql 语句

参考:https://github.com/NLPchina/elasticsearch-sql/wiki/Join

# 普通条件查询
select * from index where day = "20190722"

# 普通聚合查询
select count(*)as counts, day from index where day between '20190722' and '20190723' group by day

select count(*) from index where day = "20190722"

# 父子表 nested,childFile查询
# 子查询 nested
select * from index
where nested("message",message.day="20191218") 

# 子查询聚合 group by 只能是keyword
select  nested("message.action"),count(*) from index
where day = "20191218"
group by terms(field="message.action",nested="message")


# 关联查询 ,两个索引关联查询

select  a.agentId as a1,b.agentId as b1  from  index1 b join index2 a
on a.agentId = b.agentId 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值