zwen-lab / sql-dsl
laravel api rate limit middleware
v0.0.3
2020-09-30 08:05 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-09-29 05:29:16 UTC
README
是一个专业的将SQL查询语句转换为Elasticsearch的DSL查询语句的PHP类库。在使用Elasticsearch时,用户无需学习复杂的DSL语法,只需会写SQL语句即可,SQL-DSL类库会帮我们将其转换为复杂的DSL语句。
安装
composer require sql-dsl v0.0.3
使用方法
$sql = 'SELECT sum(a) from testindex-20200914/testtype where a="xxxxx" and create_time>=1600048800 and create_time <1600056000 group by create_time,b' $dslBody = \Zwen\SqlDsl\EsParser::sql2dsl($sql); var_dump(json_encode($dslBody));
SQL-DSL类库可以帮助我们转换为以下DSL语句
{
"index": "testindex-20200914",
"type": "testtype",
"body": {
"query": {
"bool": {
"filter": [{
"bool": {
"must": [{
"match_phrase": {
"a": {
"query": "xxxxx"
}
}
}]
}
}, {
"range": {
"create_time": {
"gte": "1600048800",
"lt": "1600056000"
}
}
}]
}
},
"aggs": {
"create_time": {
"terms": {
"field": "create_time",
"size": 1000000
},
"aggs": {
"b": {
"terms": {
"field": "b",
"size": 1000000
},
"aggs": {
"suma": {
"sum": {
"field": "a"
}
},
"top": {
"top_hits": {
"size": 1
}
}
}
}
}
}
}
}
}
支持的常用SQL语句示例
说明:未列出所有支持的SQL语句。不支持跨表或JOIN相关的SQL语句,常用单表查询的SQL语句基本上都支持。
select a, c, b from index-20200914/type where host = 'www.baidu.com' select * from index-20200914/type where host = 'www.baidu.com' e>1 and e<=10 limit 0,10 select sum(a) as a,sum(b),sum(c) from index-20200914/type where host = 'www.baidu.com' e>1 and e<=10 group by host,e