MongoDB to Elasticsearch Converter Online — Convert MongoDB Queries to ES DSL
Paste your MongoDB query above and get the equivalent Elasticsearch DSL instantly. Converts MongoDB operators to bool queries, aggregation pipelines to ES aggregations — all in your browser.
How to Convert MongoDB to Elasticsearch — Step-by-Step
Input Your MongoDB Query
Migrating from MongoDB to Elasticsearch? Paste your query — the converter handles both MongoDB shell syntax (unquoted keys) and strict JSON format. You can convert find(), findOne(), aggregate(), and countDocuments() queries.
.js or .json fileExample: MongoDB find() with Operators
A MongoDB query filtering products by status, price range, and tags:
db.products.find({ status: "active", price: { $gte: 50, $lte: 500 }, tags: { $in: ["electronics", "sale"] }, name: { $regex: "^Pro" } })
Automatic Conversion
The converter maps MongoDB operators to Elasticsearch equivalents in real time. Each query operator is translated into the corresponding Elasticsearch clause:
$gt/$gte/$lt/$lte → range, $in → terms, $regex → wildcard/prefix$and → bool.must, $or → bool.should, $ne → bool.must_not$eq → term, $exists → exists$group → terms agg with sub-aggs for $sum/$avg/$min/$maxOutput: Elasticsearch DSL
The above MongoDB query converts to this Elasticsearch bool query:
{ "query": { "bool": { "must": [ { "term": { "status": "active" } }, { "range": { "price": { "gte": 50, "lte": 500 } } }, { "terms": { "tags": ["electronics", "sale"] } }, { "prefix": { "name": "Pro" } } ] } } }
Aggregation Pipeline Conversion
MongoDB aggregation pipelines are converted to Elasticsearch aggregations. Each pipeline stage maps to a specific ES construct:
$match → query clause (same as find() conversion)$group → terms aggregation with sub-aggs for $sum, $avg, $min, $max$sort → sort parameter or order within aggregations$limit → size parameter$project → _source includes and excludesExample: MongoDB Aggregation Pipeline
Group orders by category with total revenue and average order value:
db.orders.aggregate([ { $match: { status: "completed" } }, { $group: { _id: "$category", totalRevenue: { $sum: "$amount" }, avgOrder: { $avg: "$amount" } } }, { $sort: { totalRevenue: -1 } } ])
Output: Elasticsearch Aggregation
Converted to ES terms aggregation with sub-aggregations:
{ "query": { "term": { "status": "completed" } }, "size": 0, "aggs": { "group_by_category": { "terms": { "field": "category", "order": { "totalRevenue": "desc" } }, "aggs": { "totalRevenue": { "sum": { "field": "amount" } }, "avgOrder": { "avg": { "field": "amount" } } } } } }
Copy or Download
Once your query is converted, grab the Elasticsearch DSL output and use it in your project. The output is valid JSON that works directly with the Elasticsearch REST API and Kibana Dev Tools.
.json for version control or documentationFrequently Asked Questions
What MongoDB methods are supported?
The converter supports find() and findOne() for standard document queries, aggregate() with pipeline stages including $match, $group, $sort, $limit, $skip, and $project, as well as countDocuments() for count queries. Both MongoDB shell syntax with unquoted keys and strict JSON format are accepted, so you can paste directly from mongosh, MongoDB Compass, or your application code.
How are MongoDB operators mapped to Elasticsearch?
Each MongoDB query operator maps to a specific Elasticsearch clause. $eq becomes a term query, $gt/$gte/$lt/$lte become range queries, $in becomes terms, $regex maps to wildcard or prefix depending on the pattern, and $exists becomes an exists query. For logical operators, $or maps to bool.should, $and maps to bool.must, and $ne maps to bool.must_not.
Does it convert aggregation pipelines?
Yes, the converter handles MongoDB aggregation pipelines and maps each stage to its Elasticsearch equivalent. $match becomes a query clause, $group becomes a terms aggregation with sub-aggregations for accumulators like $sum, $avg, $min, and $max. $sort maps to the sort parameter, $limit becomes size, and $project maps to _source includes and excludes.
Why migrate from MongoDB to Elasticsearch?
There are several common reasons to migrate queries from MongoDB to Elasticsearch. Elasticsearch provides built-in full-text search with relevance scoring powered by BM25, which outperforms MongoDB's text indexes for complex search scenarios. It also offers faster aggregation analytics on large datasets thanks to its inverted index architecture. Advanced text analysis features like stemming, synonyms, and fuzzy matching make Elasticsearch the stronger choice for search-heavy applications. Additionally, Elasticsearch's distributed architecture allows for horizontal scaling across clusters, and its near-real-time indexing is ideal for log analytics and metrics dashboards.
Can I use the output in Kibana?
Yes, the generated Elasticsearch DSL is fully compatible with Kibana Dev Tools. You can copy the output and paste it directly into the Kibana console to execute against your Elasticsearch cluster. The output follows the standard Elasticsearch Search API format, so it also works with any Elasticsearch client library including the official JavaScript, Python, Java, and Go clients.
Is my data sent to a server?
No, all query conversion happens entirely in your browser using client-side JavaScript. Your MongoDB queries are never transmitted to any server, making this tool safe for converting sensitive or proprietary queries. There are no API calls, no telemetry on your query content, and no data storage — the conversion logic runs locally in your browser session.
Is this converter free?
Completely free with no usage limits, rate throttling, or account requirements. All processing runs locally in your browser so there are no server costs. You can also try our related converters: Elasticsearch to MongoDB, SQL to Elasticsearch, Elasticsearch 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