将 SQL 转换为 Golang(go) 中的 Elasticsearch DSL
_____ _ _ ____ _____ ___ ____ ____ ___ _
| ____| | / \ / ___|_ _|_ _|/ ___|/ ___| / _ \ | |
| _| | | / _ \ \___ \ | | | || | \___ \| | | || |
| |___| |___ / ___ \ ___) || | | || |___ ___) | |_| || |___
|_____|_____|/_/ \_\|____/ |_| |___|\____||____/ \__\_\|_____|此工具将 SQL 转换为 Elasticsearch DSL 当前支持:
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)
}
将产生:
…如果您的 SQL 中包含一些关键字,例如 order、timestamp,请不要忘记对这些字段进行转义,具体如下:
select * from `order` where `timestamp` = 1 and `desc`.id > 0要使用此工具,您需要了解 elasticsearch 的查询术语和匹配短语查询。 将字段设置为已分析或未分析会得到不同的结果。
有关转换的更多详细信息,请参阅 wiki
暂无开放 Issues,或尚未同步最近议题。