{"id":18073467,"url":"https://github.com/iamazy/elasticsearch-sql","last_synced_at":"2025-04-05T04:11:44.962Z","repository":{"id":37736026,"uuid":"198355705","full_name":"iamazy/elasticsearch-sql","owner":"iamazy","description":"parse sql into elasticsearch dsl with antlr4","archived":false,"fork":false,"pushed_at":"2023-06-14T22:47:51.000Z","size":3644,"stargazers_count":342,"open_issues_count":16,"forks_count":90,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-03-29T03:07:46.119Z","etag":null,"topics":["antlr","antlr4","dsl","elasticsearch","high-level-rest-client","java","restful","sql"],"latest_commit_sha":null,"homepage":"https://iamazy.github.io/elasticsearch-sql/","language":"Java","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/iamazy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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,"roadmap":null,"authors":null}},"created_at":"2019-07-23T05:05:58.000Z","updated_at":"2025-03-26T05:41:27.000Z","dependencies_parsed_at":"2023-12-15T20:10:30.386Z","dependency_job_id":"fdd77c53-a27d-4471-bd29-a6c6b00bc67a","html_url":"https://github.com/iamazy/elasticsearch-sql","commit_stats":{"total_commits":509,"total_committers":7,"mean_commits":72.71428571428571,"dds":0.05108055009823187,"last_synced_commit":"6bd4459c353c0f2e9105d86ac5ab9723cd131867"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamazy%2Felasticsearch-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamazy%2Felasticsearch-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamazy%2Felasticsearch-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamazy%2Felasticsearch-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamazy","download_url":"https://codeload.github.com/iamazy/elasticsearch-sql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284950,"owners_count":20913704,"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":["antlr","antlr4","dsl","elasticsearch","high-level-rest-client","java","restful","sql"],"created_at":"2024-10-31T10:07:42.284Z","updated_at":"2025-04-05T04:11:44.939Z","avatar_url":"https://github.com/iamazy.png","language":"Java","readme":"## Description\nrewrite [elasticsearch-sql2](https://github.com/iamazy/elasticsearch-sql2) with **antlr4**, support [**jdbc**](https://github.com/iamazy/elasticsearch-sql/wiki/Jdbc)\n\n## Changelog\n[Changelog](https://github.com/iamazy/elasticsearch-sql/blob/master/CHANGELOG)\n\n## Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.iamazy.elasticsearch.dsl\u003c/groupId\u003e\n    \u003cartifactId\u003eelasticsearch-sql-all\u003c/artifactId\u003e\n    \u003cversion\u003e${latest.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n或者\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eio.github.iamazy.elasticsearch.dsl\u003c/groupId\u003e\n        \u003cartifactId\u003eelasticsearch-sql-core\u003c/artifactId\u003e\n        \u003cversion\u003e${latest.version}\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eio.github.iamazy.elasticsearch.dsl\u003c/groupId\u003e\n        \u003cartifactId\u003eelasticsearch-sql-jdbc\u003c/artifactId\u003e\n        \u003cversion\u003e${latest.version}\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n## Plugin(isql)\n\n#### Installing\n\nElasticsearch {7.x}\n```\n./bin/elasticsearch-plugin install https://github.com/iamazy/elasticsearch-sql/releases/download/{isql-version}/elasticsearch-sql-plugin-{elasticsearch-version}.zip\n```\n\n#### Usage\n\n##### 1. query dataset with sql\n```\nPOST _isql\n{\n    \"sql\":\"select * from fruit\"\n}\n```\n##### 2. parse sql into elasticsearch dsl\n```\nPOST _isql/_explain\n{\n    \"sql\":\"select * from fruit\"\n}\n```\n\n## Wiki\n[elasticsearch-sql-wiki](https://github.com/iamazy/elasticsearch-sql/wiki)\n\n## Features\n#### 1. Based on antlr4\n\u003e customize grammer of elasticsearch sql \u003cbr/\u003e\n\u003e support analyse the walk of sql ast and the relation of tokens\n\n ### Ast\n ```sql\n select name from student aggregate by terms(name,1)\u003e(terms(aa,2),[apple,cardinality(ip),terms(aaa,1)\u003e(terms(cc,10)\u003e(terms(hh,3\n)))]) limit 2,5\n ```\n ![ast](./data/images/ast.png)\n\n ### Relation of Tokens\n ![graph](./data/images/graph.png)\n \n\n#### 2. Based on elasticsearch java rest high level client\n\u003e support for request from third-party http component \u003cbr/\u003e\n\u003e cross-language \u003cbr/\u003e\n\u003e support for parsing sql into elasticsearch dsl \u003cbr/\u003e\n\u003e support x-pack \u003cbr/\u003e\n\u003e no need for request pool \u003cbr/\u003e\n\n#### 3. Integrte into elasticsearch(isql)\n\n#### Features\n- [x] [SQL Select](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#1-select-field)  \n- [x] [SQL Where](https://github.com/iamazy/elasticsearch-sql/wiki/通用搜索查询)  \n- [x] [SQL Order by (Asc \u0026 Desc)](https://github.com/iamazy/elasticsearch-sql/wiki/%E6%8E%92%E5%BA%8F#1-%E6%8E%92%E5%BA%8F)\n- [x] [SQL Group by](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [ES Aggregate by](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB#1-elasticsearch%E8%81%9A%E7%B1%BB)\n- [x] [SQL And \u0026 Or](https://github.com/iamazy/elasticsearch-sql/wiki/%E5%A4%8D%E6%9D%82%E7%BB%84%E5%90%88%E6%9F%A5%E8%AF%A2#1-bool-%E6%9F%A5%E8%AF%A2)\n- [x] [SQL In](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#4-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%B3%E9%94%AE%E8%AF%8D%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [SQL Between And](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [x] [SQL Is](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [x] [SQL Not](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [x] [SQL Null](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [ ] SQL Nvl\n- [x] [SQL Max](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [SQL Min](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [SQL Sum](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [SQL Avg](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [SQL \u003e \u0026 \u003c \u0026 \u003e= \u0026 \u003c=](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [ ] ES Explain\n- [x] [ES FullText](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES Match](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES MultiMatch](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES QueryString](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [ ] ES SimpleQueryString\n- [x] [ES HasParent](https://github.com/iamazy/elasticsearch-sql/wiki/Join%E6%9F%A5%E8%AF%A2(parent,child))\n- [x] [ES HasChild](https://github.com/iamazy/elasticsearch-sql/wiki/Join%E6%9F%A5%E8%AF%A2(parent,child))\n- [x] [ES Join](https://github.com/iamazy/elasticsearch-sql/wiki/Join%E6%9F%A5%E8%AF%A2(parent,child))\n- [x] ES Script\n- [x] [ES Fuzzy](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES Prefix](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES Regex](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES Term](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#4-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%B3%E9%94%AE%E8%AF%8D%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES Wildcard](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES Routing](https://github.com/iamazy/elasticsearch-sql/wiki/Routing%E6%9F%A5%E8%AF%A2)\n- [x] [ES Nested Query](https://github.com/iamazy/elasticsearch-sql/wiki/Nested%E7%B1%BB%E5%9E%8B%E6%9F%A5%E8%AF%A2)\n- [x] [ES Nested Aggregation](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB#3-elasticsearch-nested%E8%81%9A%E7%B1%BB)\n- [x] [ES Include \u0026 Exclude](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [x] [ES From](https://github.com/iamazy/elasticsearch-sql/wiki/%E5%88%86%E9%A1%B5)\n- [x] [ES Size](https://github.com/iamazy/elasticsearch-sql/wiki/%E5%88%86%E9%A1%B5)\n- [x] [ES Range(Number,Date)](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2)\n- [x] [ES MatchAll](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES MatchPhrase](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES MatchPhrasePrefix](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#3-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [ES DeleteByQuery](https://github.com/iamazy/elasticsearch-sql/wiki/DeleteByQuery)\n- [x] [ES Cardinality](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [ES TopHits](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB)\n- [x] [ES Nested](https://github.com/iamazy/elasticsearch-sql/wiki/Nested%E7%B1%BB%E5%9E%8B%E6%9F%A5%E8%AF%A2)\n- [x] [ES GeoDistance](https://github.com/iamazy/elasticsearch-sql/wiki/Geo%E6%9F%A5%E8%AF%A2)\n- [x] [ES GeoBoundingBox](https://github.com/iamazy/elasticsearch-sql/wiki/Geo%E6%9F%A5%E8%AF%A2)\n- [x] [ES GeoPolygon](https://github.com/iamazy/elasticsearch-sql/wiki/Geo%E6%9F%A5%E8%AF%A2)\n- [x] [ES GeoShape](https://github.com/iamazy/elasticsearch-sql/wiki/Geo%E6%9F%A5%E8%AF%A2)\n- [x] [ES GeoJsonShape](https://github.com/iamazy/elasticsearch-sql/wiki/Geo%E6%9F%A5%E8%AF%A2)\n- [x] [ES SubAggregation](https://github.com/iamazy/elasticsearch-sql/wiki/%E8%81%9A%E7%B1%BB#2-elasticsearch%E5%A4%9A%E9%87%8D%E8%81%9A%E7%B1%BB)\n- [ ] ES Scroll Id\n- [x] [ES Highlighter](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%AB%98%E4%BA%AE)\n- [ ] ES Boosting\n- [x] [ES Function Score](https://github.com/iamazy/elasticsearch-sql/wiki/%E6%89%93%E5%88%86)\n- [x] [ES Disjunction Max (DisMax)](https://github.com/iamazy/elasticsearch-sql/wiki/%E6%89%93%E5%88%86)\n- [x] [SQL Like](https://github.com/iamazy/elasticsearch-sql/wiki/%E9%80%9A%E7%94%A8%E6%90%9C%E7%B4%A2%E6%9F%A5%E8%AF%A2#4-elasticsearch%E4%B8%AD%E7%9A%84%E5%85%B3%E9%94%AE%E8%AF%8D%E6%90%9C%E7%B4%A2%E7%9A%84%E8%A1%A8%E8%BE%BE%E6%96%B9%E5%BC%8F)\n- [x] [SQL Desc](https://github.com/iamazy/elasticsearch-sql/wiki/%E6%8F%8F%E8%BF%B0%E7%B4%A2%E5%BC%95-%E5%AD%97%E6%AE%B5%E7%BB%93%E6%9E%84)\n- [x] [ES Reindex](https://github.com/iamazy/elasticsearch-sql/wiki/Reindex)\n- [x] [ES Track Total Hits](https://github.com/iamazy/elasticsearch-sql/wiki/%E5%88%86%E9%A1%B5)\n- [x] [SQL Update](https://github.com/iamazy/elasticsearch-sql/wiki/Update)\n- [x] [ES Update By Query](https://github.com/iamazy/elasticsearch-sql/wiki/Update)\n- [x] [SQL Delete](https://github.com/iamazy/elasticsearch-sql/wiki/Delete)\n- [x] [ES DeleteByQuery](https://github.com/iamazy/elasticsearch-sql/wiki/Delete)\n- [x] [SQL Insert](https://github.com/iamazy/elasticsearch-sql/wiki/Insert)\n- [x] [Java Jdbc](https://github.com/iamazy/elasticsearch-sql/wiki/Jdbc)\n\n#### Todo\n- [ ] SQL Having\n- [ ] SQL Customise Function\n- [ ] ES Analysis\n- [ ] ES Boosting\n- [ ] ...\n\n## Examples\n### 1. select,include,exclude,from,where,in,and,or,has_parent,geo_distance,limit\n```sql\nselect name,^h!age,h!gender from student where ((a in (1,2,3,4)) and has_parent(apple,bb~='fruit')) and c=1 and (coordinate = [40.0,30.0] and distance = '1km' or t='bb') limit 2,5\n```\n\u003e generate dsl\n```json\n{\n  \"from\" : 2,\n  \"size\" : 5,\n  \"query\" : {\n    \"bool\" : {\n      \"must\" : [ {\n        \"terms\" : {\n          \"a\" : [ \"1\", \"2\", \"3\", \"4\" ],\n          \"boost\" : 1.0\n        }\n      }, {\n        \"has_parent\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [ {\n                \"match\" : {\n                  \"bb\" : {\n                    \"query\" : \"'fruit'\",\n                    \"operator\" : \"OR\",\n                    \"prefix_length\" : 0,\n                    \"max_expansions\" : 50,\n                    \"fuzzy_transpositions\" : true,\n                    \"lenient\" : false,\n                    \"zero_terms_query\" : \"NONE\",\n                    \"auto_generate_synonyms_phrase_query\" : true,\n                    \"boost\" : 1.0\n                  }\n                }\n              } ],\n              \"adjust_pure_negative\" : true,\n              \"minimum_should_match\" : \"1\",\n              \"boost\" : 1.0\n            }\n          },\n          \"parent_type\" : \"apple\",\n          \"score\" : true,\n          \"ignore_unmapped\" : false,\n          \"boost\" : 1.0\n        }\n      }, {\n        \"term\" : {\n          \"c\" : {\n            \"value\" : \"1\",\n            \"boost\" : 1.0\n          }\n        }\n      } ],\n      \"should\" : [ {\n        \"geo_distance\" : {\n          \"coordinate\" : [ 30.0, 40.0 ],\n          \"distance\" : 1000.0,\n          \"distance_type\" : \"arc\",\n          \"validation_method\" : \"STRICT\",\n          \"ignore_unmapped\" : false,\n          \"boost\" : 1.0\n        }\n      }, {\n        \"term\" : {\n          \"t\" : {\n            \"value\" : \"'bb'\",\n            \"boost\" : 1.0\n          }\n        }\n      } ],\n      \"adjust_pure_negative\" : true,\n      \"minimum_should_match\" : \"1\",\n      \"boost\" : 1.0\n    }\n  },\n  \"_source\" : {\n    \"includes\" : [ \"name\", \"gender\" ],\n    \"excludes\" : [ \"age\" ]\n  }\n}\n```\n\n### 2. nested,query_string,match(~==)\n```sql\nselect name from student where (([class1, age\u003e1 and [class1.class2, name='hhha']] and c=1) or b~=='hhhhh') and query by 'apppple' limit 2,5\n```\n\u003e generate dsl\n```json\n{\n  \"from\" : 2,\n  \"size\" : 5,\n  \"query\" : {\n    \"bool\" : {\n      \"must\" : [ {\n        \"query_string\" : {\n          \"query\" : \"apppple\",\n          \"fields\" : [ ],\n          \"type\" : \"best_fields\",\n          \"default_operator\" : \"or\",\n          \"max_determinized_states\" : 10000,\n          \"enable_position_increments\" : true,\n          \"fuzziness\" : \"AUTO\",\n          \"fuzzy_prefix_length\" : 0,\n          \"fuzzy_max_expansions\" : 50,\n          \"phrase_slop\" : 0,\n          \"escape\" : false,\n          \"auto_generate_synonyms_phrase_query\" : true,\n          \"fuzzy_transpositions\" : true,\n          \"boost\" : 1.0\n        }\n      } ],\n      \"should\" : [ {\n        \"bool\" : {\n          \"must\" : [ {\n            \"nested\" : {\n              \"query\" : {\n                \"bool\" : {\n                  \"must\" : [ {\n                    \"range\" : {\n                      \"age\" : {\n                        \"from\" : \"1\",\n                        \"to\" : null,\n                        \"include_lower\" : false,\n                        \"include_upper\" : true,\n                        \"boost\" : 1.0\n                      }\n                    }\n                  }, {\n                    \"nested\" : {\n                      \"query\" : {\n                        \"bool\" : {\n                          \"must\" : [ {\n                            \"term\" : {\n                              \"name\" : {\n                                \"value\" : \"'hhha'\",\n                                \"boost\" : 1.0\n                              }\n                            }\n                          } ],\n                          \"adjust_pure_negative\" : true,\n                          \"minimum_should_match\" : \"1\",\n                          \"boost\" : 1.0\n                        }\n                      },\n                      \"path\" : \"class1.class2\",\n                      \"ignore_unmapped\" : false,\n                      \"score_mode\" : \"avg\",\n                      \"boost\" : 1.0\n                    }\n                  } ],\n                  \"adjust_pure_negative\" : true,\n                  \"minimum_should_match\" : \"1\",\n                  \"boost\" : 1.0\n                }\n              },\n              \"path\" : \"class1\",\n              \"ignore_unmapped\" : false,\n              \"score_mode\" : \"avg\",\n              \"boost\" : 1.0\n            }\n          }, {\n            \"term\" : {\n              \"c\" : {\n                \"value\" : \"1\",\n                \"boost\" : 1.0\n              }\n            }\n          } ],\n          \"adjust_pure_negative\" : true,\n          \"boost\" : 1.0\n        }\n      }, {\n        \"match_phrase\" : {\n          \"b\" : {\n            \"query\" : \"'hhhhh'\",\n            \"slop\" : 0,\n            \"zero_terms_query\" : \"NONE\",\n            \"boost\" : 1.0\n          }\n        }\n      } ],\n      \"adjust_pure_negative\" : true,\n      \"minimum_should_match\" : \"1\",\n      \"boost\" : 1.0\n    }\n  },\n  \"_source\" : {\n    \"includes\" : [ \"name\" ],\n    \"excludes\" : [ ]\n  }\n}\n```\n\n### 3. aggregate by\n```sql\nselect name from student aggregate by terms(name,1)\u003e(terms(aa,2),terms(bb,3)\u003e(terms(cc,4))),terms(age,10)\u003e(terms(weight,10))\n```\n\u003e generate dsl\n```json\n{\n  \"from\" : 0,\n  \"size\" : 15,\n  \"query\" : {\n    \"match_all\" : {\n      \"boost\" : 1.0\n    }\n  },\n  \"_source\" : {\n    \"includes\" : [ \"name\" ],\n    \"excludes\" : [ ]\n  },\n  \"aggregations\" : {\n    \"name\" : {\n      \"terms\" : {\n        \"size\" : 1,\n        \"shard_size\" : 2,\n        \"min_doc_count\" : 1,\n        \"shard_min_doc_count\" : 1,\n        \"show_term_doc_count_error\" : false,\n        \"order\" : [ {\n          \"_count\" : \"desc\"\n        }, {\n          \"_key\" : \"asc\"\n        } ]\n      },\n      \"aggregations\" : {\n        \"aa\" : {\n          \"terms\" : {\n            \"size\" : 2,\n            \"shard_size\" : 4,\n            \"min_doc_count\" : 1,\n            \"shard_min_doc_count\" : 1,\n            \"show_term_doc_count_error\" : false,\n            \"order\" : [ {\n              \"_count\" : \"desc\"\n            }, {\n              \"_key\" : \"asc\"\n            } ]\n          }\n        },\n        \"bb\" : {\n          \"terms\" : {\n            \"size\" : 3,\n            \"shard_size\" : 6,\n            \"min_doc_count\" : 1,\n            \"shard_min_doc_count\" : 1,\n            \"show_term_doc_count_error\" : false,\n            \"order\" : [ {\n              \"_count\" : \"desc\"\n            }, {\n              \"_key\" : \"asc\"\n            } ]\n          },\n          \"aggregations\" : {\n            \"cc\" : {\n              \"terms\" : {\n                \"size\" : 4,\n                \"shard_size\" : 8,\n                \"min_doc_count\" : 1,\n                \"shard_min_doc_count\" : 1,\n                \"show_term_doc_count_error\" : false,\n                \"order\" : [ {\n                  \"_count\" : \"desc\"\n                }, {\n                  \"_key\" : \"asc\"\n                } ]\n              }\n            }\n          }\n        }\n      }\n    },\n    \"age\" : {\n      \"terms\" : {\n        \"size\" : 10,\n        \"shard_size\" : 20,\n        \"min_doc_count\" : 1,\n        \"shard_min_doc_count\" : 1,\n        \"show_term_doc_count_error\" : false,\n        \"order\" : [ {\n          \"_count\" : \"desc\"\n        }, {\n          \"_key\" : \"asc\"\n        } ]\n      },\n      \"aggregations\" : {\n        \"weight\" : {\n          \"terms\" : {\n            \"size\" : 10,\n            \"shard_size\" : 20,\n            \"min_doc_count\" : 1,\n            \"shard_min_doc_count\" : 1,\n            \"show_term_doc_count_error\" : false,\n            \"order\" : [ {\n              \"_count\" : \"desc\"\n            }, {\n              \"_key\" : \"asc\"\n            } ]\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n### 4. nested aggregation,subAggregation(~)\n```sql\nselect name from student aggregate by terms(name,1)\u003e(terms(aa,2),[apple,cardinality(ip),terms(aaa,1)\u003e(terms(bb,1),terms(cc,10)\u003e(terms(hh,3),avg(age)),terms(vv,1))]) limit 2,5\n```\n\u003e generate dsl\n```json\n{\n  \"from\" : 2,\n  \"size\" : 5,\n  \"query\" : {\n    \"match_all\" : {\n      \"boost\" : 1.0\n    }\n  },\n  \"_source\" : {\n    \"includes\" : [ \"name\" ],\n    \"excludes\" : [ ]\n  },\n  \"aggregations\" : {\n    \"name\" : {\n      \"terms\" : {\n        \"size\" : 1,\n        \"shard_size\" : 2,\n        \"min_doc_count\" : 1,\n        \"shard_min_doc_count\" : 1,\n        \"show_term_doc_count_error\" : false,\n        \"order\" : [ {\n          \"_count\" : \"desc\"\n        }, {\n          \"_key\" : \"asc\"\n        } ]\n      },\n      \"aggregations\" : {\n        \"aa\" : {\n          \"terms\" : {\n            \"size\" : 2,\n            \"shard_size\" : 4,\n            \"min_doc_count\" : 1,\n            \"shard_min_doc_count\" : 1,\n            \"show_term_doc_count_error\" : false,\n            \"order\" : [ {\n              \"_count\" : \"desc\"\n            }, {\n              \"_key\" : \"asc\"\n            } ]\n          }\n        },\n        \"nested_apple\" : {\n          \"nested\" : {\n            \"path\" : \"apple\"\n          },\n          \"aggregations\" : {\n            \"ip_cardinality\" : {\n              \"cardinality\" : {\n                \"field\" : \"ip\"\n              }\n            },\n            \"aaa\" : {\n              \"terms\" : {\n                \"size\" : 1,\n                \"shard_size\" : 2,\n                \"min_doc_count\" : 1,\n                \"shard_min_doc_count\" : 1,\n                \"show_term_doc_count_error\" : false,\n                \"order\" : [ {\n                  \"_count\" : \"desc\"\n                }, {\n                  \"_key\" : \"asc\"\n                } ]\n              },\n              \"aggregations\" : {\n                \"bb\" : {\n                  \"terms\" : {\n                    \"size\" : 1,\n                    \"shard_size\" : 2,\n                    \"min_doc_count\" : 1,\n                    \"shard_min_doc_count\" : 1,\n                    \"show_term_doc_count_error\" : false,\n                    \"order\" : [ {\n                      \"_count\" : \"desc\"\n                    }, {\n                      \"_key\" : \"asc\"\n                    } ]\n                  }\n                },\n                \"cc\" : {\n                  \"terms\" : {\n                    \"size\" : 10,\n                    \"shard_size\" : 20,\n                    \"min_doc_count\" : 1,\n                    \"shard_min_doc_count\" : 1,\n                    \"show_term_doc_count_error\" : false,\n                    \"order\" : [ {\n                      \"_count\" : \"desc\"\n                    }, {\n                      \"_key\" : \"asc\"\n                    } ]\n                  },\n                  \"aggregations\" : {\n                    \"hh\" : {\n                      \"terms\" : {\n                        \"size\" : 3,\n                        \"shard_size\" : 6,\n                        \"min_doc_count\" : 1,\n                        \"shard_min_doc_count\" : 1,\n                        \"show_term_doc_count_error\" : false,\n                        \"order\" : [ {\n                          \"_count\" : \"desc\"\n                        }, {\n                          \"_key\" : \"asc\"\n                        } ]\n                      }\n                    },\n                    \"age_avg\" : {\n                      \"avg\" : {\n                        \"field\" : \"age\"\n                      }\n                    }\n                  }\n                },\n                \"vv\" : {\n                  \"terms\" : {\n                    \"size\" : 1,\n                    \"shard_size\" : 2,\n                    \"min_doc_count\" : 1,\n                    \"shard_min_doc_count\" : 1,\n                    \"show_term_doc_count_error\" : false,\n                    \"order\" : [ {\n                      \"_count\" : \"desc\"\n                    }, {\n                      \"_key\" : \"asc\"\n                    } ]\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}\n```\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/iamazy/elasticsearch-sql.svg)](https://starchart.cc/iamazy/elasticsearch-sql)\n      \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamazy%2Felasticsearch-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamazy%2Felasticsearch-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamazy%2Felasticsearch-sql/lists"}