> This page location: /docs.md > /docs/development.md > /docs/search.md > /docs/search/query/accuracy.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: bqopt, csqopt, csqeg, fsqopt, fsqeg, llpdqopt, llpdqeg, llsqopt, llsqeg, ldfqopt, ldfqeg, mtqopt, mtqeg, pqopt, pqeg, prqopt, prqeg, tqopt, tqeg, opt, eg, fuzzy, highlight, facet, index-partition, sort
-->

# How to Retrieve Query Plan and Execution Statistics

The MongoDB Search query returns information about the `$search` query plan and execution statistics when the query is run with the `explain` method enabled. When you run a query with `explain`, MongoDB Search returns a BSON (Binary Javascript Object Notation) document containing statistics and metadata that describes how the query was run internally in Lucene.

**See also:**

[explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)

**Tip: Visualize Query Plans in the Playground**

Generate and view `explain` plan summaries with the [MongoDB Search Playground.](https://www.mongodb.com/docs/search/about/playground.md#std-label-explain-search-queries)

## Syntax

```json
db.<myCollection>.explain("<verbosity>").aggregate([
  {
    $search: {
      "<operator>": {
        "<operator-options>"
      }
    }
  }
])
```

## Verbosity

Verbosity mode controls the behavior of `explain` and the amount of information returned. Value can be one of the following, in order of decreasing verbosity:

| [allPlansExecution](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) | Information about the query plan including the `stats` fields, which contain execution statistics for the query. Includes partial execution data captured during plan selection. |
| --- | --- |
| [executionStats](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) | Information about the query plan including the `stats` fields, which contain execution statistics for the query. |
| [queryPlanner](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-queryPlanner) (default) | Information about the query plan. Does not include the `stats` fields, which contain execution statistics for the query. |

**See also:**

[Verbosity Modes](https://www.mongodb.com/docs/manual/reference/command/explain/#verbosity-modes)

## Output

The query with the `explain` method returns the following fields in the `stages.$_internalSearchMongotRemote` object:

| Option | Type | Purpose |
| --- | --- | --- |
| `mongotQuery` | document | Contains the query that you ran. |
| `explain` | document | Contains the `explain` results. To learn more, see [Explain Results.](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) |
| `internalMongotBatchSizeHistory` | array of integers | Contains the size of each batch of documents that `mongot` returned to `mongod`. |

## Explain Results

The `explain` method returns a BSON (Binary Javascript Object Notation) document with the following fields in the `explain` document.

| Option | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `collectors` | document | Optional | Describes the execution statistics for the collector. If `indexPartitionExplain` is present, this is nested within each `indexPartitionExplain` instead of at the top-level. |
| `highlight` | document | Optional | Details about the [highlight](https://www.mongodb.com/docs/search/query/highlighting.md#std-label-highlight-ref) execution for the query. This is returned only if you specified [highlighting](https://www.mongodb.com/docs/search/query/highlighting.md#std-label-highlight-ref) in the query. |
| `indexPartitionExplain` | array of documents | Optional | Contains per index partition details. This is only returned if you configured two or more index partitions. |
| `metadata` | document | Optional | Contains useful metadata. |
| `query` | document | Optional | Describes the execution statistics for the query. This is not returned. If `indexPartitionExplain` is present, this is nested within each `indexPartitionExplain`, instead of at the top-level. |
| `resultMaterialization` | document | Optional | Details related to retrieving per-document data from Lucene after query execution. This is not returned for `queryPlanner` verbosity mode. |
| `resourceUsage` | document | Optional | Details the resource usage of the query when it was executed. This is not returned for `queryPlanner` verbosity mode. |

### `collectors`

The `collectors` BSON (Binary Javascript Object Notation) document contains the following fields:

| Field | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `allCollectorStats` | document | Required | Statistics of all collectors of the query. Statistics reported represent either the maximum value across all collectors used in the query or a sum of the statistic across all the sub-collectors. The timing statistics are summed to reflect the total time spent across all collectors for the entire query. To learn more, see [allCollectorStats.](https://www.mongodb.com/docs/vector-search/query/explain.md#std-label-avs-explain-search-all-collector-stats) |
| `facet` | document | Optional | Breakdown of the query that specifies [facet](https://www.mongodb.com/docs/search/query/operators-collectors/facet.md#std-label-fts-facet-ref). To learn more, see [`facet`.](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-search-facet) |
| `sort` | document | Optional | Breakdown of the query that specifies [sort](https://www.mongodb.com/docs/search/query/sort.md#std-label-sort-ref). To learn more, see [`sort`.](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-search-sort) |

#### `allCollectorStats`

The `allCollectorStats` BSON (Binary Javascript Object Notation) document describes collector statistics across all collectors specified in the query, including `facet` and `sort`. It contains the following keys:

| Field | Description |
| --- | --- |
| `collect` | Tracks the duration and number of results collected by the collector. |
| `competitiveIterator` | Statistics tracking the total duration and the number of times a `competitiveIterator` was requested from the collector. |
| `setScorer` | Statistics tracking the total duration and number of times a scorer was set on the collector. |

#### `facet`

The `facet` is a BSON (Binary Javascript Object Notation) document that details query and execution statistics when you specify a [facet](https://www.mongodb.com/docs/search/query/operators-collectors/facet.md#std-label-fts-facet-ref) in the query. It contains the following fields:

| Option | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `collectorStats` | document | Optional | Shows statistics only for the `facet` collector. The keys in here are identical to the `allCollectorStats`. You can evaluate the difference between this and the `allCollectorStats` to determine the `sort` collector execution statistics if you used `sort` in the query. |
| `createCountsStats` | document | Optional | Shows statistics related to creating the internal Lucene object that holds all of the facet groupings. It contains `generateFacetCounts` field, which returns the statistics tracking the total duration and number of times `mongot` generates the Lucene object that holds all of the facets and their counts. |
| `stringFacetFieldCardinalities` | document | Required | Maps the field being faceted on to their cardinalities for both the documents that matched the query and across the entire Lucene index. It provides the following cardinality information for each field: `queried` - Represents the facet cardinality of the field across all queried documents.; `total` - Represents the facet cardinality of the field across all documents in the index. |

#### `sort`

The `sort` is a BSON (Binary Javascript Object Notation) document that details query and execution statistics when you specify a [sort](https://www.mongodb.com/docs/search/query/sort.md#std-label-sort-ref) in the query. It contains the following fields:

| Option | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `stats` | document | Optional | Tracks statistics related to `sort` execution across all sort fields. It contains the following fields: `comparator` - Shows statistics and metadata around how the Lucene sorts the results.`setBottom` - Returns how often the current least competitive sort value is updated with a new and more competitive value. When sorting, MongoDB Search keeps track of the bottom value and if a new value surpasses the current bottom value in relevance or competitiveness, this metric is incremented.; `compareBottom` - Returns the timing and invocation statistics related to comparing the current `bottom` value with a candidate `bottom` value.; `compareTop` - Returns the timing and invocation statistics related to comparing the current `top` value with a candidate `top` value.; `setHitsThresholdReached` - Returns the timing and invocation statistics related to when the maximum number of results (`limit`) was reached.; `competitiveIterator` - Returns the timing and invocation statistics related to iterating (only) over documents that are likely to compete for top spots in the sorted results.; `setScorer` - Returns the timing and invocation statistics related to computing the score and relevance of documents.; `prunedResultIterator` - Shows the invocations and timing statistics of `nextDoc` and `advance` method calls on Lucene's `competitiveIterator`.This is not present in the output if it performs a mixed data type sort.It contains only the `nextDoc` field. |
| `fieldInfos` | document | Required | Maps the field being sorted on to the list of data types present in the index for the field. |
| `usesIndexSort` | boolean | Optional | Indicates whether the query can benefit from the index sort. A query benefits when its sort fields match the index sort or form a prefix of it. If value is: `true`, the query is eligible to use the sorted-index optimization.; `false`, the query can't benefit from the sorted index optimization. This is absent in the output if the query doesn't specify a sort or if the index doesn't have a sort specification. |

### `highlight`

The `highlight` is a BSON (Binary Javascript Object Notation) document that details query and execution statistics when you specify [highlighting](https://www.mongodb.com/docs/search/query/highlighting.md#std-label-highlight-ref) in the query. It contains the following fields:

| Option | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `resolvedHighlightPaths` | List<String> | Required | List of all the highlighted fields. If you specified a wildcard path in the `highlight` section of your query, contains a list of fully resolved document paths. |
| `stats` | QueryExecutionArea | Optional | Invocation and timing statistics related to setting up and executing highlights. It contains the following fields: `setupHighlight` - Time it took for setting up the internal Lucene objects used during the `executeHighlight` phase.; `executeHighlight` - Time it took to run highlighting over the matching documents. |

### `indexPartitionExplain`

the `indexPartitionExplain` contains [Explain Results](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) for each index partition. The top-level [`collectors`](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-search-collect-stats) and [`query`](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-search-query) are inside the `explain` information of each index partition and absent at the top-level.

### `metadata`

The `metadata` contains helpful metadata, such as the following:

| Field | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `mongotVersion` | String | Optional | Current version of `mongot`. |
| `mongotHostName` | String | Optional | Human readable label that identifies the `mongot` host. |
| `indexName` | String | Optional | MongoDB Search index used in the query. |
| `cursorOptions` | Document | Optional | Cursor options given to `mongot`. |
| `totalLuceneDocs` | Integer | Optional | Total number of index objects in the index including deleted documents. |

### `query`

The `query` BSON (Binary Javascript Object Notation) document describes the execution statistics for the query. It contains the following fields:

| Field | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `path` | string | Optional | Path to the operator, only if it isn't the root. |
| `type` | string | Required | Name of the Lucene Query that the MongoDB Search operator created. See `query` for more information. |
| `analyzer` | string | Optional | MongoDB Search [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref) used with the query. |
| `args` | document | Required | Lucene query information. See `query` for more information. |
| `stats` | document | Optional | [`stats`](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-timing-breakdown) for the query if `explain` ran with `executionStats` or `allPlansExecution` verbosity. |

#### `args`

The [explain response](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) of a search command contains information about the query executed with that command. The response in the `args` field includes structured details of what Lucene queries MongoDB Search executed to satisfy a `$search` query.

This section contains:

- Some of the Lucene queries that MongoDB Search operators create

- Lucene query options that are included in the structured summary

- Lucene query structured summary example for each Lucene query type

**Note: About the Examples**

The examples in this section are based on queries run against the [sample datasets](https://www.mongodb.com/docs/manual/sample-data.md#std-label-available-sample-datasets) with the `queryPlanner` [verbosity mode](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-verbosity). In the example response, the:

- `mongotQuery` field shows the MongoDB Search operator and the query that was run.

- `explain.type` field shows the Lucene Query that the operator created.

For complete examples, see [Examples.](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-egs)

### Options

For Lucene `BooleanQuery`, the structured summary includes details on the following options:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `must` | <[Explain Results>](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Optional | Clauses which must match. |
| `mustNot` | <[Explain Results>](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Optional | Clauses which must not match. |
| `should` | <[Explain Results>](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Optional | Clauses which should match. |
| `filter` | <[Explain Results>](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Optional | Clauses which must all match. |
| `minimumShouldMatch` | Integer | Optional | The minimum number of `should` clauses which must match. |

### Example

The following example shows the `explain` response for a query run against the `sample_airbnb.listingsAndReviews` collection.

```json
{
  "stages" : [
    {
      "$_internalSearchMongotRemote" : {
        "mongotQuery" : {
          "compound" : {
            "must" : [ {
              "compound" : {
                "should" : [ {
                  "text" : {
                    "query" : "historic",
                    "path" : "summary"
                  }
                },
                {
                  "text" : {
                    "query" : "Portugal",
                    "path" : "address.country"
                  }
                },
                {
                  "text" : {
                    "query" : "railway",
                    "path" : "transit"
                  }
                } ]
              }
            } ],
            "mustNot" : [ {
              "text" : {
                "query" : "Apartment",
                "path" : "property_type"
              }
            } ]
          }
        },
        "explain" : {
          "type" : "BooleanQuery",
          "args" : {
            "must" : [ {
              "path" : "compound.must",
              "type" : "BooleanQuery",
              "args" : {
                "must" : [ ],
                "mustNot" : [ ],
                "should" : [ 
                  {
                    "path" : "compound.must.compound.should[0]",
                    "type" : "TermQuery",
                    "args" : {
                      "path" : "summary",
                      "value" : "historic"
                    }
                  },
                  {
                    "path" : "compound.must.compound.should[1]",
                    "type" : "TermQuery",
                    "args" : {
                      "path" : "address.country",
                      "value" : "portugal"
                    }
                  },
                  {
                    "path" : "compound.must.compound.should[2]",
                    "type" : "TermQuery",
                    "args" : {
                      "path" : "transit",
                      "value" : "railway"
                    }
                  } 
                ],
                "filter" : [ ],
                "minimumShouldMatch" : 0
              }
            } ],
            "mustNot" : [ {
              "path" : "compound.mustNot",
              "type" : "TermQuery",
              "args" : {
                "path" : "property_type",
                "value" : "apartment"
              }
            } ],
            "should" : [ ],
            "filter" : [ ],
            "minimumShouldMatch" : 0
          }
        }
      },
      ...
    },
    ...
  ],
  ...
}

```

### Options

For constant score queries, the structured summary includes details on the following options:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `query` | [Explain Results](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Required | Child of the `ConstantScoreQuery`. |

### Options

For Lucene `FunctionScoreQuery` queries, the structured summary includes details on the following options:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `scoreFunction` | string | Required | Scoring expression used in the query. |
| `query` | [Explain Results](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Required | The query. |

### Options

For Lucene `LatLonPointDistanceQuery` queries, the response contains an [`stats`](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-timing-breakdown) only.

### Options

For Lucene `LatLonShapeQuery` queries, the response contains an [`stats`](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-timing-breakdown) only.

### Options

For Lucene `LongDistanceFeatureQuery`, the response contains an [`stats`](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-timing-breakdown) only.

### Options

For Lucene `MultiTermQueryConstantScoreWrapper` queries, the structured summary includes details on the following arguments:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `queries` | List<[Explain Results>](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response) | Required | List of queries. |

### Options

For Lucene `PhraseQuery` queries, the structured summary includes details on the following arguments:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `path` | String | Required | Indexed field to search. |
| `query` | String | Required | String or strings to search for. |
| `slop` | Number | Required | Allowable distance between words in the `query` phrase. |

### Options

For Lucene `PointRangeQuery` queries, the structured summary includes details on the following arguments:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `path` | String | Required | Indexed field to search. |
| `representation` | String | Optional | Numeric representation. Queries over date-typed data do not include representation. |
| `gte` | Number | Optional | Lower bound of the query. |
| `lte` | Number | Optional | Upper bound of the query. |

### Options

For term queries, the structured summary includes details on the following arguments:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `path` | String | Required | Indexed field to search. |
| `value` | String | Required | String to search for. |

### Options

Lucene queries that are not explicitly defined by another Lucene query are serialized using the default query. The structured summary includes details on the following option:

| Field | Type | Necessity | Description |
| --- | --- | --- | --- |
| `queryType` | String | Required. | Type of Lucene query. |

#### `stats`

The `explain` response for [executionStats](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) and [allPlansExecution](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) verbosity modes includes a `stats` field that contains information on how much [time](https://www.mongodb.com/docs/search/query/explain.md#std-label-timing-breakdown) a query spends in various [stages of query](https://www.mongodb.com/docs/search/query/explain.md#std-label-areas-of-query) execution.

##### Timing Breakdown

The timing breakdown describes execution statistics pertinent to an [areas of query](https://www.mongodb.com/docs/search/query/explain.md#std-label-areas-of-query) execution. The following fields show the timing breakdown:

| Field | Type | Description |
| --- | --- | --- |
| `millisElapsed` | Long | Approximate wall-clock time elapsed performing tasks in this [area](https://www.mongodb.com/docs/search/query/explain.md#std-label-areas-of-query) including the amount of time the children of the query spent in this [area](https://www.mongodb.com/docs/search/query/explain.md#std-label-areas-of-query). The value is approximate number of milliseconds elapsed while performing tasks in this area. |
| `invocationCounts` | Document | Number of invocations of tasks included in this [area](https://www.mongodb.com/docs/search/query/explain.md#std-label-areas-of-query). The value is a map of task names to their invocation count. |

##### Areas of Query

Statistics are available for the following areas of query:

| Option | Description |
| --- | --- |
| `context` | Statistics related to the execution of the Lucene query. There are two tasks whose invocation counts are enumerated in this area: `createScorer`: Scorer iterates over documents and generates a score for each document. Invocations of `createScorer` create the object responsible for scoring. Note that time associated with this task is not time spent actually scoring documents. Count includes the number of `scorerSupplier` invocations.; `createWeight`: Weight stores state associated with a query and `IndexSearcher`. Count includes the number of `createWeight` invocations. The [time](https://www.mongodb.com/docs/search/query/explain.md#std-label-timing-breakdown) spent in this area is related to the structure of the query, and is not based on the number of results that are iterated through and scored. For example: `"context" : {
  "millisElapsed" : NumberDouble(4.934751),
  "invocationCounts" : {
    "createWeight" : NumberLong(1),
    "createScorer" : NumberLong(10)
  }
}` |
| `match` | Statistics related to iterating over and matching result documents. This statistic shows the time it takes to determine which document is the next match. Time spent matching results can vary significantly depending on the nature of the query. There are two tasks whose invocation counts are enumerated in this area: `nextDoc`: Requests to advance to the next document of the result set. This involves identifying and moving past skips, or other tasks necessary to find the next match. Count includes the number of `nextDoc` and `advance` invocations.; `refineRoughMatch`: Performs a more thorough match. Some queries execute in a two-phase process where a document is first "roughly" matched, and is checked with a second, more thorough phase only after satisfying the first rough match. The `refineRoughMatch` task is the second phase of the two-phase process. Count includes the number of `refineRoughMatch` invocations. For example: `"match" : {
  "millisElapsed" : NumberDouble(4.901597),
  "invocationCounts" : {
    "nextDoc" : NumberLong(541),
    "refineRoughMatch" : NumberLong(0)
  }
}` |
| `score` | Statistics related to scoring documents in the result set. There are two tasks whose invocation counts are enumerated in this area: `score`: Scores each document in the result set. Count includes the number of `score` invocations.; `setMinCompetitiveScore`: Ignores documents whose score is less than the given value. Indicates that a query may have been able to reduce the number of scoring operations performed by ignoring documents with scores below some uncompetitive threshold. Count includes the number of `setMinCompetitiveScore` invocations. For example: `"score" : {
  "millisElapsed" : NumberDouble(3.931312),
  "invocationCounts" : {
    "score" : NumberLong(536),
    "setMinCompetitiveScore" : NumberLong(0)
  }
}` |

### `resultMaterialization`

The `resultMaterialization` document shows the amount of time `mongot` takes to accomplish the following:

Retrieve result data stored in Lucene in the form of either `_id` or `storedSource`.

Serialize the data into BSON (Binary Javascript Object Notation) format before sending it to `mongod`.

To learn more, see [`stats`.](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-timing-breakdown)

### `resourceUsage`

The `resourceUsage` document shows the resource used for running the query. It contains the following fields:

| Field | Type | Necessity | Purpose |
| --- | --- | --- | --- |
| `majorFaults` | Long | Required | Number of major page faults, which occur when the system can't find the required data in memory resulting in reading from the backing store such as disk, during query execution. |
| `minorFaults` | Long | Required | Number of minor page faults, which occur when the data is in the page cache, but hasn't yet been mapped to the process' page table. |
| `userTimeMs` | Long | Required | Amount of CPU time, in milliseconds, spent in user space. |
| `systemTimeMs` | Long | Required | Amount of CPU time, in milliseconds, spent in system space. |
| `maxReportingThreads` | Integer | Required | Maximum number of threads that `mongot` used during query execution across all batches. For non-concurrent explain queries, the value is `1`. |
| `numBatches` | Integer | Required | Total number of batches that `mongot` was requested when processing the query. |

## Examples

The following examples use the `movies` collection in the `sample_mflix` database.

**Tip:**

If you've already loaded the [sample dataset](https://www.mongodb.com/docs/manual/sample-data.md#std-label-available-sample-datasets), refer to the [MongoDB Search Quick Start](https://www.mongodb.com/docs/search/tutorial.md#std-label-fts-tutorial-ref) tutorial to create an [index definition](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) and run MongoDB Search queries.

### `allPlansExecution`

The following example uses different operators to query the `title` field with the `allPlansExecution` [verbosity](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-verbosity) mode.

### Fuzzy Example

```javascript
db.movies.explain("allPlansExecution").aggregate([
  {
    $search: {
      "text": {
        "path": "title",
        "query": "yark",
        "fuzzy": {
          "maxEdits": 1,
          "maxExpansions": 100,
        }
      }
    }
  }
])
```

**Output:**

```javascript
{
  explainVersion: '1',
  stages: [
    {
      '$_internalSearchMongotRemote': {
        mongotQuery: {
          text: {
            path: 'title',
            query: 'yark',
            fuzzy: { maxEdits: 1, maxExpansions: 100 }
          }
        },
        explain: {
          query: {
            type: 'BooleanQuery',
            args: {
              must: [],
              mustNot: [],
              should: [
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'mark' },
                      stats: {
                        context: { millisElapsed: 0 },
                        match: { millisElapsed: 0 },
                        score: { millisElapsed: 0 }
                      }
                    },
                    boost: 0.75
                  },
                  stats: {
                    context: {
                      millisElapsed: 0.209279,
                      invocationCounts: {
                        createWeight: Long('2'),
                        createScorer: Long('18')
                      }
                    },
                    match: {
                      millisElapsed: 0.028079,
                      invocationCounts: { nextDoc: Long('22') }
                    },
                    score: {
                      millisElapsed: 0.01706,
                      invocationCounts: { score: Long('16') }
                    }
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'yard' },
                      stats: {
                        context: { millisElapsed: 0 },
                        match: { millisElapsed: 0 },
                        score: { millisElapsed: 0 }
                      }
                    },
                    boost: 0.75
                  },
                  stats: {
                    context: {
                      millisElapsed: 0.136254,
                      invocationCounts: {
                        createWeight: Long('2'),
                        createScorer: Long('14')
                      }
                    },
                    match: {
                      millisElapsed: 0.008556,
                      invocationCounts: { nextDoc: Long('10') }
                    },
                    score: {
                      millisElapsed: 0.006096,
                      invocationCounts: { score: Long('6') }
                    }
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'york' },
                      stats: {
                        context: { millisElapsed: 0 },
                        match: { millisElapsed: 0 },
                        score: { millisElapsed: 0 }
                      }
                    },
                    boost: 0.75
                  },
                  stats: {
                    context: {
                      millisElapsed: 0.303568,
                      invocationCounts: {
                        createWeight: Long('2'),
                        createScorer: Long('18')
                      }
                    },
                    match: {
                      millisElapsed: 0.374856,
                      invocationCounts: { nextDoc: Long('62') }
                    },
                    score: {
                      millisElapsed: 0.892383,
                      invocationCounts: { score: Long('56') }
                    }
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'ark' },
                      stats: {
                        context: { millisElapsed: 0 },
                        match: { millisElapsed: 0 },
                        score: { millisElapsed: 0 }
                      }
                    },
                    boost: 0.6666666269302368
                  },
                  stats: {
                    context: {
                      millisElapsed: 8.379562,
                      invocationCounts: {
                        createWeight: Long('2'),
                        createScorer: Long('10')
                      }
                    },
                    match: {
                      millisElapsed: 2.073272,
                      invocationCounts: { nextDoc: Long('6') }
                    },
                    score: {
                      millisElapsed: 0.004063,
                      invocationCounts: { score: Long('4') }
                    }
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'dark' },
                      stats: {
                        context: { millisElapsed: 0 },
                        match: { millisElapsed: 0 },
                        score: { millisElapsed: 0 }
                      }
                    },
                    boost: 0.75
                  },
                  stats: {
                    context: {
                      millisElapsed: 0.679029,
                      invocationCounts: {
                        createWeight: Long('2'),
                        createScorer: Long('18')
                      }
                    },
                    match: {
                      millisElapsed: 5.500198,
                      invocationCounts: { nextDoc: Long('172') }
                    },
                    score: {
                      millisElapsed: 2.465502,
                      invocationCounts: { score: Long('166') }
                    }
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'park' },
                      stats: {
                        context: { millisElapsed: 0 },
                        match: { millisElapsed: 0 },
                        score: { millisElapsed: 0 }
                      }
                    },
                    boost: 0.75
                  },
                  stats: {
                    context: {
                      millisElapsed: 0.221919,
                      invocationCounts: {
                        createWeight: Long('2'),
                        createScorer: Long('18')
                      }
                    },
                    match: {
                      millisElapsed: 0.116139,
                      invocationCounts: { nextDoc: Long('60') }
                    },
                    score: {
                      millisElapsed: 0.056817,
                      invocationCounts: { score: Long('54') }
                    }
                  }
                }
              ],
              filter: [],
              minimumShouldMatch: 0
            },
            stats: {
              context: {
                millisElapsed: 25.303419,
                invocationCounts: { createWeight: Long('2'), createScorer: Long('12') }
              },
              match: {
                millisElapsed: 10.533183,
                invocationCounts: { nextDoc: Long('308') }
              },
              score: {
                millisElapsed: 5.501189,
                invocationCounts: { score: Long('302') }
              }
            }
          },
          collectStats: {
            allCollectorStats: {
              millisElapsed: 6.735626,
              invocationCounts: {
                collect: Long('302'),
                competitiveIterator: Long('6'),
                setScorer: Long('6')
              }
            },
            facet: { collectorStats: { millisElapsed: 0 } }
          },
          resultMaterialization: {
            stats: {
              millisElapsed: 176.613905,
              invocationCounts: { retrieveAndSerialize: Long('2') }
            }
          },
          metadata: {
            <hostname>.mongodb.netmongotVersion: '1.42.0',
            mongotHostName: '<hostname>.mongodb.net',
            indexName: 'default',
            cursorOptions: { batchSize: 108, requiresSearchSequenceToken: false },
            totalLuceneDocs: 21349
          },
          resourceUsage: {
            majorFaults: Long('99'),
            minorFaults: Long('192'),
            userTimeMs: Long('80'),
            systemTimeMs: Long('10'),
            maxReportingThreads: 1,
            numBatches: 2
          }
        },
        requiresSearchMetaCursor: false,
        internalMongotBatchSizeHistory: [ Long('108'), Long('162') ]
      },
      nReturned: Long('151'),
      executionTimeMillisEstimate: Long('83')
    },
    {
      '$_internalSearchIdLookup': {
        subPipeline: [
          { '$match': { _id: { '$eq': '_id placeholder' } } }
        ],
        totalDocsExamined: Long('151'),
        totalKeysExamined: Long('151'),
        numDocsFilteredByIdLookup: Long('0')
      },
      nReturned: Long('151'),
      executionTimeMillisEstimate: Long('88')
    }
  ],
  queryShapeHash: '6FD3791F785FA329D4ECD1171E0E5AF6772C18F5F0A7A50FC416D080A93C8CB7',
  serverInfo: {
    host: '<hostname>.mongodb.net',
    port: 27017,
    version: '8.2.0',
    gitVersion: '13e629eeccd63f00d17568fc4c12b7530fa34b54'
  },
  serverParameters: {
    ...
  },
  command: {
    aggregate: 'movies',
    pipeline: [
      {
        '$search': {
          text: {
            path: 'title',
            query: 'yark',
            fuzzy: { maxEdits: 1, maxExpansions: 100 }
          }
        }
      }
    ],
    cursor: {},
    '$db': 'sample_mflix'
  },
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1758295936, i: 19 }),
    signature: {
      hash: Binary.createFromBase64('+CanjrL9jdXPTLa2sUaNPtImkBc=', 0),
      keyId: Long('7551379485140975621')
    }
  },
  operationTime: Timestamp({ t: 1758295936, i: 19 })
}
```

### `queryPlanner`

The following example uses different operators to query the `title` field with the `queryPlanner` [verbosity](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-verbosity) mode.

### Fuzzy Example

```javascript
db.movies.explain("queryPlanner").aggregate([
  {
    $search: {
      "text": {
        "path": "title",
        "query": "yark",
        "fuzzy": {
          "maxEdits": 1,
          "maxExpansions": 100,
        }
      }
    }
  }
])
```

**Output:**

```javascript
{
  explainVersion: '1',
  stages: [
    {
      '$_internalSearchMongotRemote': {
        mongotQuery: {
          text: {
            path: 'title',
            query: 'yark',
            fuzzy: { maxEdits: 1, maxExpansions: 100 }
          }
        },
        explain: {
          query: {
            type: 'BooleanQuery',
            args: {
              must: [],
              mustNot: [],
              should: [
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'park' }
                    },
                    boost: 0.75
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'york' }
                    },
                    boost: 0.75
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'dark' }
                    },
                    boost: 0.75
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'mark' }
                    },
                    boost: 0.75
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'yard' }
                    },
                    boost: 0.75
                  }
                },
                {
                  type: 'BoostQuery',
                  args: {
                    query: {
                      type: 'TermQuery',
                      args: { path: 'title', value: 'ark' }
                    },
                    boost: 0.6666666269302368
                  }
                }
              ],
              filter: [],
              minimumShouldMatch: 0
            }
          },
          metadata: {
            <hostname>.mongodb.netmongotVersion: '1.42.0',
            mongotHostName: '<hostname>.mongodb.net',
            indexName: 'default',
            totalLuceneDocs: 21349
          }
        },
        requiresSearchMetaCursor: false
      }
    },
    {
      '$_internalSearchIdLookup': {
        subPipeline: [
          { '$match': { _id: { '$eq': '_id placeholder' } } }
        ]
      }
    }
  ],
  queryShapeHash: '6FD3791F785FA329D4ECD1171E0E5AF6772C18F5F0A7A50FC416D080A93C8CB7',
  serverInfo: {
    host: '<hostname>.mongodb.net',
    port: 27017,
    version: '8.2.0',
    gitVersion: '13e629eeccd63f00d17568fc4c12b7530fa34b54'
  },
  serverParameters: {
    ...
  },
  command: {
    aggregate: 'movies',
    pipeline: [
      {
        '$search': {
          text: {
            path: 'title',
            query: 'yark',
            fuzzy: { maxEdits: 1, maxExpansions: 100 }
          }
        }
      }
    ],
    cursor: {},
    '$db': 'sample_mflix'
  },
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1758305729, i: 1 }),
    signature: {
      hash: Binary.createFromBase64('IUnIrXR/VeUrj1cGgyEFlkoQKAM=', 0),
      keyId: Long('7551379485140975621')
    }
  },
  operationTime: Timestamp({ t: 1758305729, i: 1 })
}

```

For queries that specify a [`$limit`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit.md#mongodb-pipeline-pipe.-limit) stage in the pipeline, the `explain` results include the `mongotDocsRequested` metric, which shows the number of documents that `mongod` requested from `mongot`.

**Example:**

```shell
{
  "mongotQuery": {},
  "explain": {},
  "limit": <int>,
  "sortSpec": {},
  "mongotDocsRequested": <int>,
}
```

### `executionStats`

The following example uses the [autocomplete](https://www.mongodb.com/docs/search/query/operators-collectors/autocomplete.md#std-label-autocomplete-ref) to query the `title` field with the `executionStats` [verbosity](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-verbosity) mode.

```javascript
db.movies.explain("executionStats").aggregate([
  {
    "$search": {
      "autocomplete": {
        "path": "title",
        "query": "pre",
        "fuzzy": {
          "maxEdits": 1,
          "prefixLength": 1,
          "maxExpansions": 256
        }
      }
    }
  }
])
```

**Output:**

```javascript
{
  explainVersion: '1',
  stages: [
    {
      '$_internalSearchMongotRemote': {
        mongotQuery: {
          autocomplete: {
            path: 'title',
            query: 'pre',
            fuzzy: { maxEdits: 1, prefixLength: 1, maxExpansions: 256 }
          }
        },
        explain: {
          query: {
            type: 'BooleanQuery',
            args: {
              must: [
                {
                  type: 'MultiTermQueryConstantScoreBlendedWrapper',
                  args: {
                    queries: [
                      {
                        type: 'DefaultQuery',
                        args: { queryType: 'AutomatonQuery' },
                        stats: {
                          context: { millisElapsed: 0 },
                          match: { millisElapsed: 0 },
                          score: { millisElapsed: 0 }
                        }
                      }
                    ]
                  },
                  stats: {
                    context: {
                      millisElapsed: 12.517877,
                      invocationCounts: {
                        createWeight: Long('4'),
                        createScorer: Long('48')
                      }
                    },
                    match: {
                      millisElapsed: 0.970794,
                      invocationCounts: { nextDoc: Long('2436') }
                    },
                    score: {
                      millisElapsed: 0.638731,
                      invocationCounts: { score: Long('2420') }
                    }
                  }
                }
              ],
              mustNot: [],
              should: [
                {
                  type: 'TermQuery',
                  args: { path: 'title', value: 'pre' },
                  stats: {
                    context: {
                      millisElapsed: 1.481341,
                      invocationCounts: {
                        createWeight: Long('4'),
                        createScorer: Long('16')
                      }
                    },
                    match: { millisElapsed: 0 },
                    score: { millisElapsed: 0 }
                  }
                }
              ],
              filter: [],
              minimumShouldMatch: 0
            },
            stats: {
              context: {
                millisElapsed: 15.118651,
                invocationCounts: { createWeight: Long('4'), createScorer: Long('32') }
              },
              match: {
                millisElapsed: 1.923822,
                invocationCounts: { nextDoc: Long('2436') }
              },
              score: {
                millisElapsed: 1.954216,
                invocationCounts: { score: Long('2420') }
              }
            }
          },
          collectStats: {
            allCollectorStats: {
              millisElapsed: 4.189904,
              invocationCounts: {
                collect: Long('2420'),
                competitiveIterator: Long('16'),
                setScorer: Long('16')
              }
            },
            facet: { collectorStats: { millisElapsed: 0 } }
          },
          resultMaterialization: {
            stats: {
              millisElapsed: 21.876621,
              invocationCounts: { retrieveAndSerialize: Long('4') }
            }
          },
          metadata: {
            <hostname>.mongodb.netmongotVersion: '1.42.0',
            mongotHostName: '<hostname>.mongodb.net',
            indexName: 'default',
            cursorOptions: { batchSize: 108, requiresSearchSequenceToken: false },
            totalLuceneDocs: 21349
          },
          resourceUsage: {
            majorFaults: Long('2'),
            minorFaults: Long('242'),
            userTimeMs: Long('40'),
            systemTimeMs: Long('0'),
            maxReportingThreads: 1,
            numBatches: 4
          }
        },
        requiresSearchMetaCursor: false,
        internalMongotBatchSizeHistory: [ Long('108'), Long('162'), Long('243'), Long('365') ]
      },
      nReturned: Long('605'),
      executionTimeMillisEstimate: Long('44')
    },
    {
      '$_internalSearchIdLookup': {
        subPipeline: [
          { '$match': { _id: { '$eq': '_id placeholder' } } }
        ],
        totalDocsExamined: Long('605'),
        totalKeysExamined: Long('605'),
        numDocsFilteredByIdLookup: Long('0')
      },
      nReturned: Long('605'),
      executionTimeMillisEstimate: Long('91')
    }
  ],
  queryShapeHash: '6FD3791F785FA329D4ECD1171E0E5AF6772C18F5F0A7A50FC416D080A93C8CB7',
  serverInfo: {
    host: '<hostname>.mongodb.net',
    port: 27017,
    version: '8.2.0',
    gitVersion: '13e629eeccd63f00d17568fc4c12b7530fa34b54'
  },
  serverParameters: {
    ...
  },
  command: {
    aggregate: 'movies',
    pipeline: [
      {
        '$search': {
          autocomplete: {
            path: 'title',
            query: 'pre',
            fuzzy: { maxEdits: 1, prefixLength: 1, maxExpansions: 256 }
          }
        }
      }
    ],
    cursor: {},
    '$db': 'sample_mflix'
  },
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1758306209, i: 1 }),
    signature: {
      hash: Binary.createFromBase64('MIipFR5NAfl728L6h4ueQeZBLGM=', 0),
      keyId: Long('7551379485140975621')
    }
  },
  operationTime: Timestamp({ t: 1758306209, i: 1 })
}

```

To learn more about the `explain` response elements, see [Explain Results.](https://www.mongodb.com/docs/search/query/explain.md#std-label-explain-response)
