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

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

Step 1

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.

Paste directly: Copy from Compass, mongosh, or your code
Upload: Select a .js or .json file
Sample: See a find() with multiple operators converted to ES DSL

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

Automatic Conversion

The converter maps MongoDB operators to Elasticsearch equivalents in real time. Each query operator is translated into the corresponding Elasticsearch clause:

Operators: $gt/$gte/$lt/$lterange, $interms, $regexwildcard/prefix
Logic: $andbool.must, $orbool.should, $nebool.must_not
Equality & existence: $eqterm, $existsexists
Aggregations: $groupterms agg with sub-aggs for $sum/$avg/$min/$max

Output: 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" } }
      ]
    }
  }
}
Step 3

Aggregation Pipeline Conversion

MongoDB aggregation pipelines are converted to Elasticsearch aggregations. Each pipeline stage maps to a specific ES construct:

$matchquery clause (same as find() conversion)
$groupterms aggregation with sub-aggs for $sum, $avg, $min, $max
$sortsort parameter or order within aggregations
$limitsize parameter
$project_source includes and excludes

Example: 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" } }
      }
    }
  }
}
Step 4

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.

Copy: Paste into Kibana Dev Tools, Elasticsearch client libraries, or your application code
Download: Save as .json for version control or documentation

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