An open API service indexing awesome lists of open source software.

https://github.com/paknahad/eql

SQL into ES DSL (Write on SQL, Search on ElasticSearch)
https://github.com/paknahad/eql

dsl elasticsearch sql-parser

Last synced: 11 days ago
JSON representation

SQL into ES DSL (Write on SQL, Search on ElasticSearch)

Awesome Lists containing this project

README

          

```

EEEEEEEEEEEEEEEEEEEEEE QQQQQQQQQ LLLLLLLLLLL
E::::::::::::::::::::E QQ:::::::::QQ L:::::::::L
E::::::::::::::::::::E QQ:::::::::::::QQ L:::::::::L
EE::::::EEEEEEEEE::::EQ:::::::QQQ:::::::QLL:::::::LL
E:::::E EEEEEEQ::::::O Q::::::Q L:::::L
E:::::E Q:::::O Q:::::Q L:::::L
E::::::EEEEEEEEEE Q:::::O Q:::::Q L:::::L
E:::::::::::::::E Q:::::O Q:::::Q L:::::L
E:::::::::::::::E Q:::::O Q:::::Q L:::::L
E::::::EEEEEEEEEE Q:::::O Q:::::Q L:::::L
E:::::E Q:::::O QQQQ:::::Q L:::::L
E:::::E EEEEEEQ::::::O Q::::::::Q L:::::L LLLLLL
EE::::::EEEEEEEE:::::EQ:::::::QQ::::::::QLL:::::::LLLLLLLLL:::::L
E::::::::::::::::::::E QQ::::::::::::::Q L::::::::::::::::::::::L
E::::::::::::::::::::E QQ:::::::::::Q L::::::::::::::::::::::L
EEEEEEEEEEEEEEEEEEEEEE QQQQQQQQ::::QQLLLLLLLLLLLLLLLLLLLLLLLL
Q:::::Q
QQQQQQ
```

[![Build Status](https://travis-ci.org/meysampg/eql.svg?branch=master)](https://travis-ci.org/meysampg/eql)
[![Maintainability](https://api.codeclimate.com/v1/badges/c3377ea017b632d00320/maintainability)](https://codeclimate.com/github/meysampg/eql/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c3377ea017b632d00320/test_coverage)](https://codeclimate.com/github/meysampg/eql/test_coverage)

Overview
-----------

This project will a try to be a `php` equivalent of [elasticsql](https://github.com/cch123/elasticsql).

Currently support:

- [ ] sql and expression
- [ ] sql or expression
- [ ] equal(=) support
- [ ] not equal(!=) support
- [ ] gt(>) support
- [ ] gte(>=) support
- [ ] lt(<) support
- [ ] lte(<=) support
- [ ] sql in (eg. id in (1,2,3) ) expression
- [ ] sql not in (eg. id not in (1,2,3) ) expression
- [ ] paren bool support (eg. where (a=1 or b=1) and (c=1 or d=1))
- [ ] sql like expression (currently use match phrase, perhaps will change to wildcard in the future)
- [ ] sql order by support
- [ ] sql limit support
- [ ] sql not like expression
- [ ] field missing check
- [ ] support aggregation like count(\*), count(field), min(field), max(field), avg(field)
- [ ] support aggregation like stats(field), extended_stats(field), percentiles(field) which are not standard sql function
- [ ] null check expression(is null/is not null)
- [ ] join expression
- [ ] having support

Usage
-------------

`> composer require meysampg/eql`

Demo :
```php
1 order by id desc limit 100,10
";

function main()
{
$dsl = Parser::buildFrom($sql);
print_r(json_encode($dsl));
}

```

will produce :
```json
{
"query": {
"bool": {
"must": [
{
"match": {
"a": {
"query": "1",
"type": "phrase"
}
}
},
{
"match": {
"x": {
"query": "三个男人",
"type": "phrase"
}
}
},
{
"range": {
"create_time": {
"from": "2015-01-01T00:00:00+0800",
"to": "2016-01-01T00:00:00+0800"
}
}
},
{
"range": {
"process_id": {
"gt": "1"
}
}
}
]
}
},
"from": 100,
"size": 10,
"sort": [
{
"id": "desc"
}
]
}
```

If your sql contains some keywords, eg. order, timestamp, don't forget to escape these fields as follows:

```
select * from `order` where `timestamp` = 1 and `desc`.id > 0
```