Elasticsearch to SQL Converter Online — Convert ES DSL Queries to SQL
Paste your Elasticsearch DSL query above and get the equivalent SQL instantly. Converts bool queries to WHERE, aggregations to GROUP BY, range queries to comparison operators, and more — everything runs in your browser.
How to Convert Elasticsearch to SQL — Step-by-Step
Input Your Elasticsearch Query
Got an Elasticsearch query you need to understand as SQL? Paste the JSON body from your Kibana Dev Tools, application code, or API response. You can include the GET /index/_search line — the converter extracts the index name automatically.
.json fileExample Elasticsearch Input
A typical bool query combining term, range, and terms filters:
GET /products/_search { "query": { "bool": { "must": [ { "term": { "status": "active" } }, { "range": { "price": { "gte": 50 } } }, { "terms": { "category": ["electronics", "clothing"] } } ] } } }
Automatic Conversion to SQL
The converter maps Elasticsearch query types to standard SQL:
WHERE ... AND ...WHERE ... OR ...WHERE NOT ...IN ('a', 'b')>= / <= comparisonsLIKE with % patternsIS NOT NULLORDER BYSQL Output
The bool query from Step 1 produces this SQL statement:
SELECT * FROM products WHERE status = 'active' AND price >= 50 AND category IN ('electronics', 'clothing')
Aggregation to GROUP BY
Elasticsearch aggregations are converted into SQL GROUP BY clauses with the appropriate aggregate functions. Terms aggregations become grouping columns, while sub-aggregations like sum, avg, min, and max map to their SQL equivalents.
Elasticsearch Aggregation
A terms aggregation grouped by category with sum and avg sub-aggregations:
{ "size": 0, "aggs": { "by_category": { "terms": { "field": "category" }, "aggs": { "total_revenue": { "sum": { "field": "revenue" } }, "avg_price": { "avg": { "field": "price" } } } } } }
SQL Output
The equivalent SQL with GROUP BY and aggregate functions:
SELECT category, SUM(revenue) AS total_revenue, AVG(price) AS avg_price FROM table_name GROUP BY category
Copy or Download
.sql fileFrequently Asked Questions — Elasticsearch to SQL
What Elasticsearch query types are supported?
The converter supports all common Elasticsearch query types: term and terms for exact matching, match and match_phrase for full-text search, wildcard and prefix for pattern matching, range for numeric and date comparisons, exists for null checks, and bool with all four clauses (must, must_not, should, filter). It also handles terms aggregations with sub-aggregations (sum, avg, min, max, value_count), sort, size, and from.
Can I include the GET /index/_search line?
Yes — the converter automatically detects and extracts the index name from GET /index/_search or POST /index/_search lines, just as you would use them in Kibana Console. The extracted index name becomes the SQL FROM table name. If you paste just the JSON body without a request line, the table name defaults to "table_name" — you can easily find-and-replace it in the output.
How are aggregations converted to GROUP BY?
Elasticsearch terms aggregations become SQL GROUP BY clauses. The field specified in the terms aggregation becomes the grouping column. Sub-aggregations are mapped to their SQL equivalents: sum becomes SUM(), avg becomes AVG(), min/max become MIN()/MAX(), and value_count becomes COUNT(). Each sub-aggregation name is used as the SQL column alias.
Does it handle nested bool queries?
Yes. The converter fully supports nested bool queries with multiple levels of must, must_not, should, and filter clauses. Nested conditions are properly parenthesized in the SQL output to preserve the original query logic. For example, a should nested inside a must produces AND (... OR ...) with correct grouping.
What happens with match vs term queries?
In Elasticsearch, term performs exact matching on the stored value without analysis, while match passes the value through the field's analyzer for full-text search. Since SQL does not have an equivalent concept of analyzed vs non-analyzed fields, the converter maps both to equality comparisons (=). Similarly, match_phrase is also converted to an equality check. Keep this distinction in mind when migrating queries — you may want to add LIKE or full-text search functions depending on your SQL database.
Is my data safe?
Your queries are processed entirely in your browser using client-side JavaScript — nothing is sent to any server. The conversion logic parses the same Elasticsearch Search API format that Kibana uses. Your Elasticsearch queries never leave your machine, making this tool fully private and secure for production queries.
Is this converter free?
Completely free with no limits on usage — no account or registration required. Convert as many Elasticsearch queries to SQL as you need. Also check out our other free converters: SQL to Elasticsearch, SQL to MongoDB, MongoDB to SQL, and DynamoDB to SQL.
Related Tools
SQL to MongoDB
Convert SQL queries to MongoDB query syntax with aggregation pipeline support
MongoDB to SQL
Convert MongoDB queries and aggregation pipelines to equivalent SQL statements
SQL to DynamoDB
Convert SQL queries to AWS DynamoDB query and scan operations with PartiQL support
DynamoDB to SQL
Convert AWS DynamoDB query and scan operations to equivalent SQL statements
MongoDB Query Formatter
Format, beautify, and validate MongoDB queries with proper indentation and syntax highlighting
MongoDB to DynamoDB
Convert MongoDB queries to AWS DynamoDB query operations and vice versa