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

Elasticsearch to MongoDB Converter Online — Convert ES DSL to MongoDB Queries

Paste your Elasticsearch DSL query above and get the equivalent MongoDB query instantly. Converts bool queries to MongoDB operators, aggregations to aggregate pipelines — all in your browser.

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

Step 1

Input Your Elasticsearch Query

Moving from Elasticsearch to MongoDB? Paste the _search body from Kibana or your code. You can include the GET /index/_search line and the converter will extract the index name to use as the MongoDB collection name.

Paste: Copy from Kibana Dev Tools or your application code
Upload: Select a .json file
Sample: See a bool query with term, range, terms, wildcard, and must_not converted

Example: Elasticsearch Bool Query

An Elasticsearch query searching for active products priced at $50 or more in specific categories:

{
  "query": {
    "bool": {
      "must": [
        { "term": { "status": "active" } },
        { "range": { "price": { "gte": 50 } } },
        { "terms": { "category": ["electronics", "accessories"] } }
      ],
      "must_not": [
        { "term": { "discontinued": true } }
      ]
    }
  },
  "sort": [{ "price": "desc" }],
  "size": 20
}
Step 2

Automatic Conversion

The converter maps Elasticsearch query types to MongoDB operators:

term/match → direct equality, terms$in, range$gt/$gte/$lt/$lte
wildcard$regex, prefix$regex: "^prefix", exists$exists
bool.must → merged filter / $and, bool.should$or, must_not$not
sort.sort(), size.limit(), from.skip(), _source → projection

Result: MongoDB find() Query

The bool query above converts to this MongoDB equivalent:

db.collection.find({
  "status": "active",
  "price": { "$gte": 50 },
  "category": { "$in": ["electronics", "accessories"] },
  "discontinued": { "$ne": true }
})
.sort({ "price": -1 })
.limit(20)
Step 3

Aggregation Conversion

Elasticsearch aggregations with terms buckets and sub-aggregations are converted to MongoDB aggregate() pipelines using $group stages. Metrics like sum, avg, min, max, and value_count map directly to their MongoDB equivalents.

Input: Elasticsearch Terms Aggregation with Sub-Aggs

Group orders by status and calculate total revenue and average amount per group:

{
  "size": 0,
  "aggs": {
    "by_status": {
      "terms": { "field": "status" },
      "aggs": {
        "total_revenue": { "sum": { "field": "amount" } },
        "avg_amount": { "avg": { "field": "amount" } }
      }
    }
  }
}

Output: MongoDB aggregate() Pipeline

The aggregation converts to a $group stage with accumulators:

db.collection.aggregate([
  {
    "$group": {
      "_id": "$status",
      "total_revenue": { "$sum": "$amount" },
      "avg_amount": { "$avg": "$amount" }
    }
  }
])
Step 4

Copy or Download

Once the conversion is complete, grab the MongoDB output and use it immediately in your preferred tool or workflow.

Copy: Paste into MongoDB Compass or mongosh
Download: Save as .js for use in scripts and CI/CD pipelines

Frequently Asked Questions

What Elasticsearch query types are converted?

The converter supports all common term-level queries including term (exact match), terms (multi-value match via $in), range (mapped to $gt/$gte/$lt/$lte), exists (mapped to $exists: true), and prefix (mapped to $regex: "^value"). Full-text queries like match and match_phrase are converted to direct equality conditions. Wildcard queries are converted to MongoDB $regex patterns with appropriate escaping. Bool queries with must, must_not, should, and filter clauses are also fully supported, along with aggregations and pagination parameters.

Does it handle aggregations?

Yes. Elasticsearch terms aggregations are converted to MongoDB $group stages where the field becomes the _id of the group. Sub-aggregations are mapped to their MongoDB accumulator equivalents: sum becomes $sum, avg becomes $avg, min becomes $min, max becomes $max, and value_count becomes { $sum: 1 }. If your Elasticsearch query contains both a query block and an aggs block, the converter outputs an aggregate() pipeline with a $match stage followed by the $group stage.

How does bool query mapping work?

Elasticsearch bool queries are the most common compound query type and map cleanly to MongoDB. The must array clauses are merged into a single MongoDB filter object when possible, or wrapped in $and when field names conflict. The should array maps to $or, allowing any of the contained conditions to match. The must_not array applies negation using $not or $ne depending on the clause type. The filter context works identically to must in MongoDB since MongoDB does not distinguish between scoring and non-scoring query contexts. Nested bool queries are recursively converted so deeply nested conditions are preserved.

Can I include the GET /index/_search line?

Yes. The converter auto-detects lines like GET /products/_search or POST /orders/_search at the top of your input. When detected, the index name (e.g., "products" or "orders") is extracted and used as the MongoDB collection name in the output, so instead of db.collection.find() you get db.products.find(). If the line is not present, the converter uses a generic collection placeholder. This makes it easy to paste queries directly from Kibana Dev Tools without manual cleanup.

Does it convert sort, size, and from?

Yes. Elasticsearch sort fields are converted to MongoDB .sort() with 1 for ascending and -1 for descending. The size parameter maps to .limit() and from maps to .skip(), giving you the same pagination behavior. The _source field, which controls which fields Elasticsearch returns, is converted to a MongoDB projection object passed as the second argument to find(). Multi-field sorting is supported and preserves field order.

Is my data sent to a server?

No. All conversion processing happens entirely in your browser using client-side JavaScript. Your Elasticsearch queries never leave your machine, so it is safe to use with proprietary query structures, internal field names, or sensitive business logic. There is no server component, no API call, and no data logging. You can verify this by checking the network tab in your browser's developer tools while using the converter.

Is this converter free?

Completely free with no usage limits and no account required. The tool runs entirely in your browser and is available 24/7. Also try our related tools: MongoDB to Elasticsearch, SQL to Elasticsearch, SQL to MongoDB, and Elasticsearch to SQL.