cch123/elasticsql
cch123/elasticsql has 1,190 GitHub stars and 198 forks. GitHot measured +1 stars in 24 hours and +1 in 7 days. Last checked 2026-11-11 17:08 UTC. Last push 2023-08-06.
So werden diese Zahlen gemessen
convert sql to elasticsearch DSL in golang(go)
Gemessener Sternzuwachs
- in 24h
- +1
- in 7 days
- +1
- in 15 days
- Aktualisierung verzögert
- in 1 month
- Aktualisierung verzögert
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
README.md
Original _____ _ _ ____ _____ ___ ____ ____ ___ _
| ____| | / \ / ___|_ _|_ _|/ ___|/ ___| / _ \ | |
| _| | | / _ \ \___ \ | | | || | \___ \| | | || |
| |___| |___ / ___ \ ___) || | | || |___ ___) | |_| || |___
|_____|_____|/_/ \_\|____/ |_| |___|\____||____/ \__\_\|_____|
Overview
This tool converts sql to elasticsearch dsl
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
go get -u github.com/cch123/elasticsql
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 :
{
"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"
}
]
}
aaa
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
Warning
To 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.
Details
For more details of convertion, please refer to the wiki
Other info
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!
License
MIT
Ähnliche Projekte entdecken
Asabeneh/30-Days-Of-Python
Die Programmier-Challenge 30 Days of Python ist eine Schritt-für-Schritt-Anleitung, um die Programmiersprache Python in 30 Tagen zu lernen. Diese Challenge kann mehr als 100 Tage dauern. Gehe in deinem eigenen Tempo vor. Diese Videos können ebenfalls helfen: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,618 Sternegrafana/grafana
Offene und kombinierbare Plattform für Observability und Datenvisualisierung. Visualisiert Metriken, Logs und Traces aus mehreren Quellen wie Prometheus, Loki, Elasticsearch, InfluxDB, Postgres und vielen weiteren.
77,859 Sterneredis/redis
Für Entwickler, die echtzeitfähige, datengesteuerte Anwendungen erstellen, ist Redis der bevorzugte, schnellste und funktionsreichste Cache, Datenstrukturserver und die entsprechende Abfrageengine für Dokumente und Vektoren.
77,472 Sterneapache/superset
Apache Superset ist eine Plattform für Datenvisualisierung und Datenexploration.
75,495 Sterne