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

SQL to Elasticsearch Converter Online — Convert SQL to Elasticsearch DSL Queries

Paste your SQL query above and get the equivalent Elasticsearch DSL query instantly. Converts WHERE to bool queries, LIKE to wildcards, GROUP BY to aggregations — all in your browser. Everything runs client-side using JavaScript, so your queries never leave your machine.

How to Convert SQL to Elasticsearch — Step-by-Step

Step 1

Input Your SQL Query

Need to query Elasticsearch but only know SQL? Paste your SELECT query and the converter handles the translation to Elasticsearch's JSON-based Search API.

Paste directly: Copy your SQL query and paste — conversion happens instantly
Upload a file: Click "Upload" to select a .sql file
Load a sample: Click "Sample" to see a SELECT with WHERE, ORDER BY, and LIMIT converted

Example SQL Input

A typical query selecting products with filters, sorting, and a row limit:

SELECT name, price
FROM products
WHERE category = 'electronics'
  AND price > 50
ORDER BY price ASC
LIMIT 20
Step 2

Automatic Conversion to Elasticsearch DSL

The converter maps each SQL clause to its Elasticsearch Query DSL equivalent:

SELECT columns: Becomes _source array to return only the fields you need
WHERE: Becomes bool.must with term, range, terms, wildcard, and exists queries
LIKE: %text% becomes wildcard, text% becomes prefix
ORDER BY: Becomes sort array with field and order direction
LIMIT / OFFSET: Becomes size and from parameters for pagination

Elasticsearch DSL Output

The SQL query from Step 1 converts to this Elasticsearch request body:

// GET /products/_search
{
  "_source": ["name", "price"],
  "query": {
    "bool": {
      "must": [
        { "term": { "category": "electronics" } },
        { "range": { "price": { "gt": 50 } } }
      ]
    }
  },
  "sort": [{ "price": "asc" }],
  "size": 20
}
Step 3

GROUP BY & Aggregation Conversion

SQL GROUP BY with aggregate functions maps to Elasticsearch terms aggregations with nested sub-aggregations. The converter handles COUNT, SUM, AVG, MIN, and MAX automatically.

SQL with GROUP BY

SELECT category,
  COUNT(*) AS total,
  SUM(price) AS revenue
FROM products
GROUP BY category

Elasticsearch Aggregation Output

{
  "size": 0,
  "aggs": {
    "group_by_category": {
      "terms": { "field": "category" },
      "aggs": {
        "total": { "value_count": { "field": "_id" } },
        "revenue": { "sum": { "field": "price" } }
      }
    }
  }
}

Notice that size: 0 is set because aggregation queries typically don't need individual hits — only the bucket results. Each SQL aggregate function maps to its Elasticsearch metric aggregation equivalent.

Step 4

Copy or Download

Once you have the converted Elasticsearch DSL, export it in the way that suits your workflow:

Copy to clipboard: Paste into Kibana Dev Tools, your application code, or use with curl and the REST API
Download: Save as a .json file for version control or sharing with your team
Try other converters: Convert the reverse with Elasticsearch to SQL, or try SQL to MongoDB and SQL to DynamoDB

Frequently Asked Questions — SQL to Elasticsearch

What SQL features are supported?

The converter supports SELECT with column selection (mapped to _source), WHERE with all comparison operators (=, !=, >, <, >=, <=), LIKE (to wildcard/prefix), IN (to terms), BETWEEN (to range), IS NULL/IS NOT NULL (to exists), AND/OR boolean logic, GROUP BY with aggregate functions (COUNT, SUM, AVG, MIN, MAX), ORDER BY with ASC/DESC, LIMIT, and OFFSET.

Does Elasticsearch support JOINs?

No — Elasticsearch is a search and analytics engine, not a relational database. It doesn't support SQL-style JOINs. The standard approach is to denormalize your data by flattening related records into a single index at index time. For use cases where you need relationships, consider nested objects or parent-child mappings. If you need JOIN support, try SQL to MongoDB which supports $lookup.

Can I use the output in Kibana?

Yes — the output includes the GET /index/_search line and the JSON body, which you can paste directly into Kibana Dev Tools console. Open Kibana, navigate to Management > Dev Tools (or press Ctrl+/), paste the output, and click the green play button to execute. The response appears in the right pane with your query results formatted as JSON.

How does GROUP BY convert to aggregations?

SQL GROUP BY maps to an Elasticsearch terms aggregation that creates buckets for each unique value. Aggregate functions become sub-aggregations: COUNT(*) becomes value_count, SUM(field) becomes sum, AVG(field) becomes avg, and MIN/MAX map directly. The converter also sets size: 0 since aggregation-only queries don't need individual document hits.

Does it handle LIKE queries?

Yes. SQL LIKE patterns are mapped to the most efficient Elasticsearch query type. A pattern like %text% (contains) becomes a wildcard query with *text*. A pattern like text% (starts with) becomes a prefix query, which is significantly faster because it can use the inverted index directly. The _ single-character wildcard is mapped to ? in Elasticsearch syntax.

Is my data sent to a server?

No. All conversion happens entirely in your browser using client-side JavaScript. Your SQL queries never leave your machine — there are no API calls, no server-side processing, and nothing is logged or stored. This makes it safe to use with proprietary queries and internal schema names.

Is this converter free?

Completely free with no limits on usage. No account or registration required — convert as many SQL queries as you need. Also check out: Elasticsearch to SQL, SQL to MongoDB, SQL to DynamoDB, and MongoDB Query Formatter.