Loading Elasticsearch to SQL Converter...
Please wait a moment

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

Step 1

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.

Paste directly: Copy the _search body from Kibana or your code
Upload a file: Click "Upload" to select a .json file
Load a sample: Click "Sample" to see a bool query with terms, range, and wildcard converted

Example 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"] } }
      ]
    }
  }
}
Step 2

Automatic Conversion to SQL

The converter maps Elasticsearch query types to standard SQL:

bool.must: Becomes WHERE ... AND ...
bool.should: Becomes WHERE ... OR ...
bool.must_not: Becomes WHERE NOT ...
terms: Becomes IN ('a', 'b')
range (gte/lte): Becomes >= / <= comparisons
wildcard/prefix: Becomes LIKE with % patterns
exists: Becomes IS NOT NULL
sort: Becomes ORDER BY

SQL 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')
Step 3

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
Step 4

Copy or Download

Copy to clipboard: Paste into your SQL client, documentation, or migration script
Download: Save as a .sql file
Try other converters: Go the other way with SQL to Elasticsearch, or convert to MongoDB or DynamoDB. Format SQL output with the SQL Formatter

Frequently 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.