{"id":13412412,"url":"https://github.com/cch123/elasticsql","last_synced_at":"2025-05-15T08:05:20.960Z","repository":{"id":41380881,"uuid":"66441536","full_name":"cch123/elasticsql","owner":"cch123","description":"convert sql to elasticsearch DSL in golang(go)","archived":false,"fork":false,"pushed_at":"2023-08-06T11:05:11.000Z","size":166,"stargazers_count":1187,"open_issues_count":12,"forks_count":199,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-04-14T13:07:33.857Z","etag":null,"topics":["dsl","elastic","elasticsearch","go","golang","search","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cch123.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-08-24T07:29:43.000Z","updated_at":"2025-04-11T06:08:37.000Z","dependencies_parsed_at":"2022-09-02T00:23:33.627Z","dependency_job_id":null,"html_url":"https://github.com/cch123/elasticsql","commit_stats":{"total_commits":114,"total_committers":6,"mean_commits":19.0,"dds":"0.21052631578947367","last_synced_commit":"e0400a1fdc13d248fc3138097fb7976d6328aca8"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch123%2Felasticsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch123%2Felasticsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch123%2Felasticsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cch123%2Felasticsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cch123","download_url":"https://codeload.github.com/cch123/elasticsql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301430,"owners_count":22047904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","elastic","elasticsearch","go","golang","search","sql"],"created_at":"2024-07-30T20:01:24.387Z","updated_at":"2025-05-15T08:05:20.894Z","avatar_url":"https://github.com/cch123.png","language":"Go","funding_links":[],"categories":["开源类库","Database Drivers","Go","Open source library","数据库驱动程序","數據庫驅動","数据库驱动","Repositories","数据库驱动`连接和操作数据库工具`","Data Integration Frameworks","Generators","NoSQL Databases","\u003cspan id=\"数据库驱动-database-drivers\"\u003e数据库驱动 Database Drivers\u003c/span\u003e"],"sub_categories":["数据库","Search and Analytic Databases","Database","Advanced Console UIs","检索及分析资料库","高級控制台界面","高级控制台界面","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"```\n _____ _         _     ____ _____ ___  ____  ____   ___   _\n| ____| |       / \\   / ___|_   _|_ _|/ ___|/ ___| / _ \\ | |\n|  _| | |      / _ \\  \\___ \\ | |  | || |    \\___ \\| | | || |\n| |___| |___  / ___ \\  ___) || |  | || |___  ___) | |_| || |___\n|_____|_____|/_/   \\_\\|____/ |_| |___|\\____||____/ \\__\\_\\|_____|\n```\n\nOverview\n-----------\n[![Build Status](https://travis-ci.org/cch123/elasticsql.svg?branch=master)](https://travis-ci.org/cch123/elasticsql)\n[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/cch123/elasticsql)\n[![Coverage Status](https://coveralls.io/repos/github/cch123/elasticsql/badge.svg?branch=master)](https://coveralls.io/github/cch123/elasticsql?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/cch123/elasticsql)](https://goreportcard.com/report/github.com/cch123/elasticsql)\n\n\n\nThis tool converts sql to elasticsearch dsl\n\nCurrently support:\n\n- [x] sql and expression\n- [x] sql or expression\n- [x] equal(=) support\n- [x] not equal(!=) support\n- [x] gt(\u003e) support\n- [x] gte(\u003e=) support\n- [x] lt(\u003c) support\n- [x] lte(\u003c=) support\n- [x] sql in (eg. id in (1,2,3) ) expression\n- [x] sql not in (eg. id not in (1,2,3) ) expression\n- [x] paren bool support (eg. where (a=1 or b=1) and (c=1 or d=1))\n- [x] sql like expression (currently use match phrase, perhaps will change to wildcard in the future)\n- [x] sql order by support\n- [x] sql limit support\n- [x] sql not like expression\n- [x] field missing check\n- [x] support aggregation like count(\\*), count(field), min(field), max(field), avg(field)\n- [x] support aggregation like stats(field), extended_stats(field), percentiles(field) which are not standard sql function\n- [ ] null check expression(is null/is not null)\n- [ ] join expression\n- [ ] having support\n\nUsage\n-------------\n\n\u003e go get -u github.com/cch123/elasticsql\n\nDemo :\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/cch123/elasticsql\"\n)\n\nvar sql = `\nselect * from aaa\nwhere a=1 and x = '三个男人'\nand create_time between '2015-01-01T00:00:00+0800' and '2016-01-01T00:00:00+0800'\nand process_id \u003e 1 order by id desc limit 100,10\n`\n\nfunc main() {\n    dsl, esType, _ := elasticsql.Convert(sql)\n    fmt.Println(dsl)\n    fmt.Println(esType)\n}\n\n```\nwill produce :\n```json\n{\n    \"query\": {\n        \"bool\": {\n            \"must\": [\n                {\n                    \"match\": {\n                        \"a\": {\n                            \"query\": \"1\",\n                            \"type\": \"phrase\"\n                        }\n                    }\n                },\n                {\n                    \"match\": {\n                        \"x\": {\n                            \"query\": \"三个男人\",\n                            \"type\": \"phrase\"\n                        }\n                    }\n                },\n                {\n                    \"range\": {\n                        \"create_time\": {\n                            \"from\": \"2015-01-01T00:00:00+0800\",\n                            \"to\": \"2016-01-01T00:00:00+0800\"\n                        }\n                    }\n                },\n                {\n                    \"range\": {\n                        \"process_id\": {\n                            \"gt\": \"1\"\n                        }\n                    }\n                }\n            ]\n        }\n    },\n    \"from\": 100,\n    \"size\": 10,\n    \"sort\": [\n        {\n            \"id\": \"desc\"\n        }\n    ]\n}\n\naaa\n```\n\nIf your sql contains some keywords, eg. order, timestamp, don't forget to escape these fields as follows:\n\n```\nselect * from `order` where `timestamp` = 1 and `desc`.id \u003e 0\n```\n\nWarning\n------------\nTo use this tool, you need to understand the term query and match phrase query of elasticsearch.\n\nSetting a field to analyzed or not analyzed will get different results.\n\nDetails\n------------\nFor more details of convertion, please refer to the [wiki](https://github.com/cch123/elasticsql/wiki)\n\nOther info\n------------\nWhen writing this tool, I tried to avoid the deprecated dsl filters and aggregations, so it is compatible with most versions of the elasticsearch\n\nIf you have any advices or ideas, welcome to submit an issue or Pull Request!\n\nLicense\n-----------\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcch123%2Felasticsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcch123%2Felasticsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcch123%2Felasticsql/lists"}