-
Notifications
You must be signed in to change notification settings - Fork 4
2.将SQL语句转换成ElasticSearch查询的DSL语言
yesAnd edited this page Sep 6, 2023
·
1 revision
lwe es [可选参数] <SQL语句>
这个命令可以帮我们从繁琐的ES查询语法中解脱出来,它可以将sql语句转换成响应的DSL,并且以curl命令的形式输出,这样服务器上也可以方便的使用。 当前版本支持的SQL操作
✅select
- and
- or
- =
- < <= > >=
- in not in
- like not like
- order by
- limit
- group by
- join
- having support
❌ update
❌ delete
❌ insert
es子命令的使用也非常简单,例如:
lwe es -p 'select * from user where age >18 order by create_time desc limit 10,10'
其中:
-p, --pretty Beautify DSL
,该参数用于美化生成的DSL结果
生成的结果如下:
curl -XPOST -H "Content-Type: application/json" -u {username}:{password} {ip:port}/user/_search?pretty -d '{
"from": 10,
"query": {
"bool": {
"must": [
{
"range": {
"age": {
"gt": "18"
}
}
}
]
}
},
"size": 10,
"sort": [
{
"create_time": "desc"
}
]
}'