convert sql to elasticsearch DSL in golang(go)
_____ _ _ ____ _____ ___ ____ ____ ___ _
| ____| | / \ / ___|_ _|_ _|/ ___|/ ___| / _ \ | |
| _| | | / _ \ \___ \ | | | || | \___ \| | | || |
| |___| |___ / ___ \ ___) || | | || |___ ___) | |_| || |___
|_____|_____|/_/ \_\|____/ |_| |___|\____||____/ \__\_\|_____|This tool converts sql to elasticsearch dsl
Currently support:
Demo :
package main
import (
"fmt"
"github.com/cch123/elasticsql"
)
var sql = `
select * from aaa
where a=1 and x = '三个男人'
and create_time between '2015-01-01T00:00:00+0800' and '2016-01-01T00:00:00+0800'
and process_id > 1 order by id desc limit 100,10
`
func main() {
dsl, esType, _ := elasticsql.Convert(sql)
fmt.Println(dsl)
fmt.Println(esType)
}
will produce :
…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 > 0To use this tool, you need to understand the term query and match phrase query of elasticsearch.
Setting a field to analyzed or not analyzed will get different results.
For more details of convertion, please refer to the wiki
When writing this tool, I tried to avoid the deprecated dsl filters and aggregations, so it is compatible with most versions of the elasticsearch
If you have any advices or ideas, welcome to submit an issue or Pull Request!
MIT
No open issues yet, or sync has not completed.