Docs 菜单
Docs 主页
/
MongoDB Atlas
/ /

检索查询计划和执行统计信息

在此页面上

  • 语法
  • 详细程度
  • 解释结果
  • collectors
  • allCollectorStats
  • facet
  • sort
  • highlight
  • indexPartitionExplain
  • metadata
  • query
  • args
  • stats
  • resultMaterialization
  • resourceUsage
  • 示例
  • allPlansExecution
  • queryPlanner
  • executionStats

在启用 方法的情况下运行查询时, Atlas Search查询会返回有关 查询计划和执行统计信息的信息。当您使用 运行查询时, Atlas Search返回一个$search explainexplainBSON文档,其中包含统计信息和元数据,描述了如何在Lucene内部运行查询。

提示

另请参阅:

explain 命令

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

详细程度模式控制 explain 行为和返回的信息量。值可以是以下值之一:

有关查询计划的信息,包括 stats 字段,其中包含查询的执行统计信息。

有关查询计划的信息,包括 stats 字段,其中包含查询的执行统计信息。

queryPlanner(默认)

有关查询计划的信息。不包括 stats 字段,其中包含查询的执行统计信息。

提示

另请参阅:

explain结果是包含以下字段的BSON文档。

选项
类型
必要性
用途

collectors

文档

Optional

描述收集器的执行统计信息。 explain 不会在 indexPartitionExplain 的顶层返回此字段。相反,explain 会在每个 indexPartitionExplain 中返回此值。

highlight

文档

Optional

有关 突出显示查询执行情况的详细信息。仅当您在查询中指定突出显示时才返回此值。

indexPartitionExplain

文档数组

Optional

包含每个索引分区的详细信息。仅当配置了两个或更多索引分区时才会返回此信息。

metadata

文档

Optional

包含有用的元数据。

query

文档

Optional

描述查询的执行统计信息。它不存在于 indexPartitionExplain 的顶层。

resultMaterialization

文档

Optional

有关在查询执行后从Lucene检索每个文档数据的详细信息。 queryPlanner 详细模式不会返回此值。

resourceUsage

文档

Optional

详细说明执行查询时的资源使用情况。 queryPlanner 详细模式不会返回此值。

collectors是一个包含以下字段的BSON文档:

选项
类型
必要性
用途

allCollectorStats

文档

必需

查询的所有收集器的统计信息。统计数据表示查询中使用的所有收集器的最大值,并且是所有子收集器的总和。计时统计信息相加求和,以反映整个查询中所有收集器所花费的总时间。要学习;了解详情,请参阅allCollectorStats

facet

文档

Optional

指定分面(Facet)的查询明细。要学习;了解详情,请参阅facet

sort

文档

Optional

指定 sort 的查询明细。要学习;了解详情,请参阅sort

allCollectorStats是一个BSON文档,描述查询中指定的所有收集器(包括 facetsort )的收集器统计信息。它包含以下键:

collect

跟踪收集器收集的持续时间和结果数量。

competitiveIterator

跟踪总持续时间和从收集器请求 competitiveIterator 的次数的统计信息。

setScorer

跟踪在收集器上设立记分器的总持续时间和次数的统计信息。

facet是一份BSON文档,其中详细说明了当您在查询中指定分面(Facet)时的查询和执行统计信息。它包含以下字段:

选项
类型
必要性
用途

collectorStats

文档

Optional

仅显示 facet 收集器的统计信息。此处的键与 allCollectorStats 相同。如果您在查询中使用了 sort,则可以评估其与 allCollectorStats 之间的差异,以确定 sort 收集器执行统计信息。

createCountsStats

文档

Optional

显示与创建保存所有分面(Facet)分组的内部Lucene对象相关的统计信息。它包含 generateFacetCounts字段,该字段返回跟踪 mongot 生成保存所有分面及其计数的Lucene对象的总持续时间和次数的统计信息。

stringFacetFieldCardinalities

文档

必需

将字段映射到与查询匹配的文档以及整个Lucene索引中的关联基数。它为每个字段提供以下关联基数信息:

  • queried — 表示所有查询文档中字段的分面(Facet)关联基数。

  • total — 表示索引中所有文档中字段的分面(Facet)关联基数。

sort是一份BSON文档,其中详细说明了当您在查询中指定排序时的查询和执行统计信息。它包含以下字段:

选项
类型
必要性
用途

stats

文档

Optional

跟踪与所有排序字段的 sort 执行相关的统计信息。它包含以下字段:

  • comparator — 显示有关Lucene如何对结果进行排序的统计信息和元数据。

    • setBottom — 返回将当前竞争性最低的排序值更新为更具竞争性的新值的频率。排序时, Atlas Search会追踪谷值,如果新值在相关性或竞争力方面超过当前谷值,则该指标会递增。

    • compareBottom — 返回与将当前 bottom 值与候选 bottom 值进行比较相关的计时和调用统计信息。

    • compareTop — 返回与将当前 top 值与候选 top 值进行比较相关的计时和调用统计信息。

    • setHitsThresholdReached — 返回与何时达到最大结果数 (limit) 相关的计时和调用统计信息。

    • competitiveIterator —(仅)返回可能争夺排序结果前列位置的文档迭代相关的计时和调用统计信息。

    • setScorer — 返回与计算文档分数和相关性相关的计时和调用统计信息。

  • prunedResultIterator — 显示 Lucene 的 competitiveIteratornextDocadvance 方法调用的调用次数和时间统计信息。

    注意

    如果执行混合数据类型排序,则不会出现在输出中。

    它仅包含 nextDoc字段。

fieldInfos

文档

必需

将要排序的字段映射到该字段索引中存在的数据类型列表。

highlight是一份BSON文档,当您在查询中指定突出显示时,其中详细说明了查询和执行统计信息。它包含以下字段:

选项
类型
必要性
用途

resolvedHighlightPaths

列表<String>

必需

所有突出显示的字段的列表。如果在查询的 highlight 部分指定了通配符路径,则包含完全解析的文档路径的列表。

stats

QueryExecutionArea

Optional

与设置和执行亮点相关的调用和计时统计。它包含以下字段:

  • setupHighlight — 设置在 executeHighlight 阶段使用的内部Lucene对象所花费的时间。

  • executeHighlight — 对匹配文档进行运行所花费的时间。

indexPartitionExplain包含每个索引分区的解释结果。顶层的collectorsquery explain位于每个索引分区的 数据中,并且不在顶层。

metadata 包含有用的元数据,如下所示:

选项
类型
必要性
用途

mongotVersion

字符串

Optional

mongot 的当前版本。

mongotHostName

字符串

Optional

用于标识 mongot托管的人类可读标签。

indexName

字符串

Optional

查询中使用的Atlas Search索引。

cursorOptions

文档

Optional

为mongot提供的游标选项。

totalLuceneDocs

整型

Optional

索引中的 Lucene 文档总数,包括已删除的文档。

explain 响应是一个 BSON 文档,其中的键和值描述了查询的执行统计数据。结果集中的 explain 文档包含以下字段:

选项
类型
必要性
用途

path

字符串

Optional

操作符的路径,前提是它不是根目录。

type

字符串

必需

Atlas Search操作符创建的Lucene查询的名称。有关更多信息,请参阅 query

analyzer

字符串

Optional

用于查询的 Atlas Search 分析器

args

文档

必需

Lucene查询信息。有关更多信息,请参阅 query

stats

文档

Optional

stats如果explain executionStats以 或allPlansExecution 详细程度运行,则用于查询的 。

搜索命令的解释响应包含有关使用该命令执行的查询的信息。args 字段中的响应包括Atlas Search为满足$search 查询而执行的Lucene查询的结构化详细信息。

本节包含:

  • Atlas Search 操作符创建的一些 Lucene 查询

  • 结构化摘要中包含的 Lucene 查询选项

  • 每个 Lucene 查询类型的 Lucene 查询结构化摘要示例

注意

关于示例

本部分中的示例基于对具有 queryPlanner详细模式的示例数据运行的查询。在示例响应中,:

  • mongotQuery 字段显示 Atlas Search 操作符和已运行的查询。

  • explain.type 字段显示操作符创建的 Lucene 查询。

有关完整示例,请参阅示例。

BooleanQuery

对于 Lucene BooleanQuery,结构化摘要包含有关以下选项的详细信息:

字段
类型
必要性
说明

must

Optional

必须匹配的条款。

mustNot

Optional

不得匹配的子句。

should

Optional

应匹配的子句。

filter

Optional

必须全部匹配的子句。

minimumShouldMatch

整型

Optional

必须匹配的最小 should 子句数量。

ConstantScoreQuery

对于恒定得分查询,结构化摘要包括以下选项的详细信息:

字段
类型
必要性
说明

query

必需

ConstantScoreQuery 的子项。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "equals" : {
7 "path" : "host.host_identity_verified",
8 "value" : true
9 }
10 },
11 "explain" : {
12 "type" : "ConstantScoreQuery",
13 "args" : {
14 "query" : {
15 "type" : "TermQuery",
16 "args" : {
17 "path" : "host.host_identity_verified",
18 "value" : "T"
19 }
20 }
21 }
22 }
23 }
24 },
25 {
26 "$_internalSearchIdLookup" : { }
27 }
28 ],
29 ...
30}
FunctionScoreQuery

对于 Lucene FunctionScoreQuery 查询,结构化摘要包含有关以下选项的详细信息:

字段
类型
必要性
说明

scoreFunction

字符串

必需

查询中使用的评分表达式。

query

必需

查询。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "near" : {
7 "path" : "accomodates",
8 "origin" : 8,
9 "pivot" : 2
10 }
11 },
12 "explain" : {
13 "type" : "BooleanQuery",
14 "args" : {
15 "must" : [ ],
16 "mustNot" : [ ],
17 "should" : [
18 {
19 "type" : "BooleanQuery",
20 "args" : {
21 "must" : [ ],
22 "mustNot" : [ ],
23 "should" : [
24 {
25 "type" : "FunctionScoreQuery",
26 "args" : {
27 "scoreFunction" : "expr(pivot / (pivot + abs(origin - value)))",
28 "query" : {
29 "type" : "LongDistanceFeatureQuery",
30 "args" : { },
31 "stats" : { }
32 }
33 }
34 }
35 ],
36 "filter" : [
37 {
38 "type" : "PointRangeQuery",
39 "args" : {
40 "path" : "accomodates",
41 "representation" : "double",
42 "gte" : 8.000000000000002,
43 "lte" : NaN
44 }
45 }
46 ],
47 "minimumShouldMatch" : 0
48 }
49 },
50 {
51 "type" : "LongDistanceFeatureQuery",
52 "args" : { },
53 "stats" : { }
54 }
55 ],
56 "filter" : [ ],
57 "minimumShouldMatch" : 0
58 }
59 }
60 },
61 ...
62 },
63 ...
64 ],
65 ...
66}
LatLonPointDistanceQuery

对于LuceneLatLonPointDistanceQuery 查询,响应仅包含stats

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "geoWithin" : {
7 "path" : "address.location",
8 "circle" : {
9 "radius" : 4800,
10 "center" : {
11 "type" : "Point",
12 "coordinates" : [
13 -122.419472,
14 37.765302
15 ]
16 }
17 }
18 }
19 },
20 "explain" : {
21 "type" : "LatLonPointDistanceQuery",
22 "args" : { }
23 }
24 }
25 },
26 ...
27 ],
28 ...
29}
LatLonShapeQuery

对于LuceneLatLonShapeQuery 查询,响应仅包含stats

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "geoShape" : {
7 "path" : "address.location",
8 "relation" : "within",
9 "geometry" : {
10 "type" : "Polygon",
11 "coordinates" : [
12 [
13 [ -74.3994140625, 40.5305017757 ],
14 [ -74.7290039063, 40.5805846641 ],
15 [ -74.7729492188, 40.9467136651 ],
16 [ -74.0698242188, 41.1290213475 ],
17 [ -73.65234375, 40.9964840144 ],
18 [ -72.6416015625, 40.9467136651 ],
19 [ -72.3559570313, 40.7971774152 ],
20 [ -74.3994140625, 40.5305017757 ]
21 ]
22 ]
23 }
24 }
25 },
26 "explain" : {
27 "type" : "LatLonShapeQuery",
28 "args" : { }
29 }
30 },
31 ...
32 },
33 ...
34 ],
35 ...
36}
LongDistanceFeatureQuery

对于LuceneLongDistanceFeatureQuery ,响应仅包含stats

以下示例显示了针对 sample_mflix.movies 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "near" : {
7 "path" : "released",
8 "origin" : ISODate("1915-09-13T00:00:00Z"),
9 "pivot" : 7776000000
10 }
11 },
12 "explain" : {
13 "type" : "LongDistanceFeatureQuery",
14 "args" : { }
15 }
16 },
17 ...
18 },
19 ...
20 ],
21 ...
22}
MultiTermQueryConstantScoreWrapper

对于 Lucene MultiTermQueryConstantScoreWrapper 查询,结构化摘要包含有关以下参数的详细信息:

字段
类型
必要性
说明

queries

列表

必需

查询列表。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "regex" : {
7 "path" : "access",
8 "query" : "full(.{0,5})",
9 "allowAnalyzedField" : true
10 }
11 },
12 "explain" : {
13 "type" : "MultiTermQueryConstantScoreWrapper",
14 "args" : {
15 "queries" : [
16 {
17 "type" : "DefaultQuery",
18 "args" : {
19 "queryType" : "RegexpQuery"
20 }
21 }
22 ]
23 }
24 }
25 },
26 ...
27 },
28 ...
29 ],
30 ...
31}
PhraseQuery

对于 Lucene PhraseQuery 查询,结构化摘要包含有关以下参数的详细信息:

字段
类型
必要性
说明

path

字符串

必需

要搜索的索引字段。

query

字符串

必需

要搜索的一个或多个字符串。

slop

数值

必需

query 短语中单词之间允许的距离。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "phrase" : {
7 "path" : "description",
8 "query" : "comfortable apartment",
9 "slop" : 2
10 }
11 },
12 "explain" : {
13 "type" : "PhraseQuery",
14 "args" : {
15 "path" : "description",
16 "query" : "[comfortable, apartment]",
17 "slop" : 2
18 }
19 }
20 },
21 ...
22 },
23 ...
24 ],
25 ...
26}
PointRangeQuery

对于 Lucene PointRangeQuery 查询,结构化摘要包含有关以下参数的详细信息:

字段
类型
必要性
说明

path

字符串

必需

要搜索的索引字段。

representation

字符串

Optional

数字表示形式。对日期类型数据的查询不包括表示形式。

gte

数值

Optional

查询的下限。

lte

数值

Optional

查询的上限。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "range" : {
7 "path" : "number_of_reviews",
8 "gt" : 5
9 }
10 },
11 "explain" : {
12 "type" : "BooleanQuery",
13 "args" : {
14 "must" : [ ],
15 "mustNot" : [ ],
16 "should" : [
17 {
18 "type" : "PointRangeQuery",
19 "args" : {
20 "path" : "number_of_reviews",
21 "representation" : "double",
22 "gte" : 5.000000000000001
23 }
24 },
25 {
26 "type" : "PointRangeQuery",
27 "args" : {
28 "path" : "number_of_reviews",
29 "representation" : "int64",
30 "gte" : NumberLong(6)
31 }
32 }
33 ],
34 "filter" : [ ],
35 "minimumShouldMatch" : 0
36 }
37 }
38 },
39 ...
40 },
41 ...
42 ],
43 ...
44}
TermQuery

对于术语查询,结构化摘要包括有关以下参数的详细信息:

字段
类型
必要性
说明

path

字符串

必需

要搜索的索引字段。

value

字符串

必需

要搜索的字符串。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "queryString" : {
7 "defaultPath" : "summary",
8 "query" : "quiet"
9 }
10 },
11 "explain" : {
12 "type" : "TermQuery",
13 "args" : {
14 "path" : "summary",
15 "value" : "quiet"
16 }
17 }
18 },
19 ...
20 },
21 ...
22 ],
23 ...
24}
Default

未由其他 Lucene 查询显式定义的 Lucene 查询将使用默认查询进行序列化。结构化摘要包含有关以下选项的详细信息:

字段
类型
必要性
说明

queryType

字符串

必需。

Lucene 查询的类型。

以下示例显示了针对 sample_airbnb.listingsAndReviews 集合运行的查询的 explain 响应。

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "near" : {
7 "origin" : {
8 "type" : "Point",
9 "coordinates" : [
10 -8.61308,
11 41.1413
12 ]
13 },
14 "pivot" : 1000,
15 "path" : "address.location"
16 }
17 },
18 "explain" : {
19 "type" : "DefaultQuery",
20 "args" : {
21 "queryType" : "LatLonPointDistanceFeatureQuery"
22 }
23 }
24 },
25 ...
26 },
27 ...
28 ],
29 ...
30}

executionStatsallPlansExecution 详细模式的explain 响应包含一个stats 字段,该字段包含有关查询在 查询执行的各个阶段所 花费的 时间 的信息。

时间细分描述了与查询执行区域相关的执行统计信息。 以下字段显示时间细分:

字段
类型
说明

millisElapsed

Long

在此区域中执行任务所花费的大致挂钟时间,包括查询的子级在此区域中花费的时间。该值是在此区域中执行任务时经过的近似毫秒数。

invocationCounts

Docuemnt

调用此区域中包含的任务的次数。该值是任务名称到其调用计数的映射。

统计信息可用于以下查询领域:

选项
说明

context

与 Lucene 查询执行相关的统计信息。 此区域中枚举了两个任务的调用计数:

createScorer

评分器遍历文档并为每个文档生成分数。 调用createScorer会创建负责评分的对象。 请注意,与此任务相关的时间不是实际对文档进行评分所花费的时间。 计数包括scorerSupplier调用次数。

createWeight

权重存储与查询和IndexSearcher关联的状态。 计数包括createWeight调用次数。

此区域花费的时间与查询的结构有关,而不是基于迭代和评分的结果数量。

例如:

"context" : {
"millisElapsed" : NumberDouble(4.934751),
"invocationCounts" : {
"createWeight" : NumberLong(1),
"createScorer" : NumberLong(10)
}
}

match

与遍历和匹配结果文档相关的统计信息。 此统计信息显示确定下一个匹配的文档所需的时间。 根据查询的性质,匹配结果所花费的时间可能会有很大差异。 此区域中枚举了两个任务的调用计数:

nextDoc

请求前进到结果集的下一个文档。 这涉及识别并移动过去的跳过,或查找下一个匹配项所需的其他任务。 计数包括nextDocadvance调用的次数。

refineRoughMatch

执行更彻底的匹配。 某些查询以双阶段过程执行,其中首先对文档进行“粗略”匹配,仅在满足第一次粗略匹配后才使用第二个更彻底的阶段进行检查。 refineRoughMatch任务是双阶段进程的第二阶段。 计数包括refineRoughMatch调用次数。

例如:

"match" : {
"millisElapsed" : NumberDouble(4.901597),
"invocationCounts" : {
"nextDoc" : NumberLong(541),
"refineRoughMatch" : NumberLong(0)
}
}

score

与结果集中的文档评分相关的统计信息。 此区域中枚举了两个任务的调用计数:

score

对结果集中的每个文档进行评分。 计数包括score调用次数。

setMinCompetitiveScore

忽略分数低于给定值的文档。 表示查询也许能够通过忽略分数低于某个非竞争阈值的文档来减少执行的评分操作数。 计数包括setMinCompetitiveScore调用次数。

例如:

"score" : {
"millisElapsed" : NumberDouble(3.931312),
"invocationCounts" : {
"score" : NumberLong(536),
"setMinCompetitiveScore" : NumberLong(0)
}
}

resultMaterialization 跟踪 mongot 完成以下操作所需的时间:

  1. 检索以 _idstoredSource 形式存储在Lucene中的结果数据。

  2. 在将数据发送到 之前,将数据序列化为BSON格式。mongod

resourceUsage 跟踪用于运行查询的资源。它包含以下字段:

选项
类型
必要性
用途

majorFaults

Long

必需

主要页面错误的数量,当系统在查询执行期间无法在内存中找到所需数据,导致从磁盘等后端存储读取数据时,就会发生主要页面错误。

minorFaults

Long

必需

次要页面错误的数量,当数据位于页面缓存但尚未映射到进程的页表时发生。

userTimeMs

Long

必需

在用户空间中花费的 CPU 时间量(以毫秒为单位)。

systemTimeMs

Long

必需

在系统空间中花费的 CPU 时间量(以毫秒为单位)。

maxReportingThreads

整型

必需

mongot 在所有批处理的查询执行期间使用的最大线程数。对于非并发解释查询,该值为 1

numBatches

整型

必需

处理查询时请求的 mongot 批处理总数。

以下示例使用 sample_mflix 数据库中的 movies 集合。

提示

如果您已经加载示例数据集,请按照 Atlas Search 入门教程,创建索引定义并运行 Atlas Search 查询。

以下示例使用不同的操作符以 详细模式查询title allPlansExecution字段。

db.movies.explain("allPlansExecution").aggregate([
{
$search: {
"text": {
"path": "title",
"query": "yark",
"fuzzy": {
"maxEdits": 1,
"maxExpansions": 100,
}
}
}
}
])
1{
2 explainVersion: '1',
3 stages: [
4 {
5 '$_internalSearchMongotRemote': {
6 mongotQuery: {
7 text: {
8 path: 'title',
9 query: 'yark',
10 fuzzy: { maxEdits: 1, maxExpansions: 100 }
11 }
12 },
13 explain: {
14 query: {
15 type: 'BooleanQuery',
16 args: {
17 must: [],
18 mustNot: [],
19 should: [
20 {
21 type: 'BoostQuery',
22 args: {
23 query: {
24 type: 'TermQuery',
25 args: { path: 'title', value: 'dark' },
26 stats: {
27 context: { millisElapsed: 0 },
28 match: { millisElapsed: 0 },
29 score: { millisElapsed: 0 }
30 }
31 },
32 boost: 0.75
33 },
34 stats: {
35 context: {
36 millisElapsed: 0.403983,
37 invocationCounts: {
38 createWeight: Long('1'),
39 createScorer: Long('18')
40 }
41 },
42 match: {
43 millisElapsed: 0.094254,
44 invocationCounts: { nextDoc: Long('89') }
45 },
46 score: {
47 millisElapsed: 0.077043,
48 invocationCounts: { score: Long('83') }
49 }
50 }
51 },
52 {
53 type: 'BoostQuery',
54 args: {
55 query: {
56 type: 'TermQuery',
57 args: { path: 'title', value: 'ark' },
58 stats: {
59 context: { millisElapsed: 0 },
60 match: { millisElapsed: 0 },
61 score: { millisElapsed: 0 }
62 }
63 },
64 boost: 0.6666666269302368
65 },
66 stats: {
67 context: {
68 millisElapsed: 0.248528,
69 invocationCounts: {
70 createWeight: Long('1'),
71 createScorer: Long('8')
72 }
73 },
74 match: {
75 millisElapsed: 0.067561,
76 invocationCounts: { nextDoc: Long('3') }
77 },
78 score: {
79 millisElapsed: 0.001649,
80 invocationCounts: { score: Long('2') }
81 }
82 }
83 },
84 {
85 type: 'BoostQuery',
86 args: {
87 query: {
88 type: 'TermQuery',
89 args: { path: 'title', value: 'mark' },
90 stats: {
91 context: { millisElapsed: 0 },
92 match: { millisElapsed: 0 },
93 score: { millisElapsed: 0 }
94 }
95 },
96 boost: 0.75
97 },
98 stats: {
99 context: {
100 millisElapsed: 0.337083,
101 invocationCounts: {
102 createWeight: Long('1'),
103 createScorer: Long('12')
104 }
105 },
106 match: {
107 millisElapsed: 0.006489,
108 invocationCounts: { nextDoc: Long('11') }
109 },
110 score: {
111 millisElapsed: 0.013741,
112 invocationCounts: { score: Long('8') }
113 }
114 }
115 },
116 {
117 type: 'BoostQuery',
118 args: {
119 query: {
120 type: 'TermQuery',
121 args: { path: 'title', value: 'park' },
122 stats: {
123 context: { millisElapsed: 0 },
124 match: { millisElapsed: 0 },
125 score: { millisElapsed: 0 }
126 }
127 },
128 boost: 0.75
129 },
130 stats: {
131 context: {
132 millisElapsed: 0.395528,
133 invocationCounts: {
134 createWeight: Long('1'),
135 createScorer: Long('16')
136 }
137 },
138 match: {
139 millisElapsed: 0.091681,
140 invocationCounts: { nextDoc: Long('32') }
141 },
142 score: {
143 millisElapsed: 0.137827,
144 invocationCounts: { score: Long('27') }
145 }
146 }
147 },
148 {
149 type: 'BoostQuery',
150 args: {
151 query: {
152 type: 'TermQuery',
153 args: { path: 'title', value: 'york' },
154 stats: {
155 context: { millisElapsed: 0 },
156 match: { millisElapsed: 0 },
157 score: { millisElapsed: 0 }
158 }
159 },
160 boost: 0.75
161 },
162 stats: {
163 context: {
164 millisElapsed: 0.150681,
165 invocationCounts: {
166 createWeight: Long('1'),
167 createScorer: Long('16')
168 }
169 },
170 match: {
171 millisElapsed: 0.067298,
172 invocationCounts: { nextDoc: Long('33') }
173 },
174 score: {
175 millisElapsed: 0.038636,
176 invocationCounts: { score: Long('28') }
177 }
178 }
179 },
180 {
181 type: 'BoostQuery',
182 args: {
183 query: {
184 type: 'TermQuery',
185 args: { path: 'title', value: 'yard' },
186 stats: {
187 context: { millisElapsed: 0 },
188 match: { millisElapsed: 0 },
189 score: { millisElapsed: 0 }
190 }
191 },
192 boost: 0.75
193 },
194 stats: {
195 context: {
196 millisElapsed: 0.104308,
197 invocationCounts: {
198 createWeight: Long('1'),
199 createScorer: Long('8')
200 }
201 },
202 match: {
203 millisElapsed: 0.002445,
204 invocationCounts: { nextDoc: Long('4') }
205 },
206 score: {
207 millisElapsed: 0.00233,
208 invocationCounts: { score: Long('3') }
209 }
210 }
211 }
212 ],
213 filter: [],
214 minimumShouldMatch: 0
215 },
216 stats: {
217 context: {
218 millisElapsed: 12.8127,
219 invocationCounts: { createWeight: Long('1'), createScorer: Long('12') }
220 },
221 match: {
222 millisElapsed: 0.761076,
223 invocationCounts: { nextDoc: Long('157') }
224 },
225 score: {
226 millisElapsed: 0.857125,
227 invocationCounts: { score: Long('151') }
228 }
229 }
230 },
231 collectors: {
232 allCollectorStats: {
233 millisElapsed: 2.061296,
234 invocationCounts: {
235 collect: Long('151'),
236 competitiveIterator: Long('6'),
237 setScorer: Long('6')
238 }
239 },
240 facet: { collectorStats: { millisElapsed: 0 } }
241 },
242 resultMaterialization: {
243 stats: {
244 millisElapsed: 17.759502,
245 invocationCounts: { retrieveAndSerialize: Long('1') }
246 }
247 },
248 metadata: {
249 mongotVersion: '1.43.1',
250 mongotHostName: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
251 indexName: 'default',
252 totalLuceneDocs: 21349
253 },
254 resourceUsage: {
255 majorFaults: Long('0'),
256 minorFaults: Long('98'),
257 userTimeMs: Long('30'),
258 systemTimeMs: Long('0'),
259 maxReportingThreads: 1,
260 numBatches: 1
261 }
262 },
263 requiresSearchMetaCursor: true
264 },
265 nReturned: Long('0'),
266 executionTimeMillisEstimate: Long('108')
267 },
268 {
269 '$_internalSearchIdLookup': {},
270 nReturned: Long('0'),
271 executionTimeMillisEstimate: Long('108')
272 }
273 ],
274 queryShapeHash: '6FD3791F785FA329D4ECD1171E0E5AF6772C18F5F0A7A50FC416D080A93C8CB7',
275 serverInfo: {
276 host: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
277 port: 27017,
278 version: '8.0.4',
279 gitVersion: 'bc35ab4305d9920d9d0491c1c9ef9b72383d31f9'
280 },
281 serverParameters: {
282 ...
283 },
284 command: {
285 aggregate: 'movies',
286 pipeline: [
287 {
288 '$search': {
289 text: {
290 path: 'title',
291 query: 'yark',
292 fuzzy: { maxEdits: 1, maxExpansions: 100 }
293 }
294 }
295 }
296 ],
297 cursor: {},
298 '$db': 'sample_mflix'
299 },
300 ok: 1,
301 '$clusterTime': {
302 clusterTime: Timestamp({ t: 1738081279, i: 12 }),
303 signature: {
304 hash: Binary.createFromBase64('DM3imkEw1qT23M2n/b/JibqB1Fg=', 0),
305 keyId: Long('7462787091647168517')
306 }
307 },
308 operationTime: Timestamp({ t: 1738081279, i: 12 })
309}
db.movies.explain("allPlansExecution").aggregate([
{
$search: {
"text": {
"path": "title",
"query": "prince"
},
"highlight": {
"path": "title",
"maxNumPassages": 1,
"maxCharsToExamine": 40
}
}
},
{
$project: {
"description": 1,
"_id": 0,
"highlights": { "$meta": "searchHighlights" }
}
}
])
1{
2 explainVersion: '1',
3 stages: [
4 {
5 '$_internalSearchMongotRemote': {
6 mongotQuery: {
7 text: { path: 'title', query: 'prince' },
8 highlight: { path: 'title', maxNumPassages: 1, maxCharsToExamine: 40 }
9 },
10 explain: {
11 query: {
12 type: 'TermQuery',
13 args: { path: 'title', value: 'prince' },
14 stats: {
15 context: {
16 millisElapsed: 1.034149,
17 invocationCounts: { createWeight: Long('1'), createScorer: Long('10') }
18 },
19 match: {
20 millisElapsed: 0.050591,
21 invocationCounts: { nextDoc: Long('29') }
22 },
23 score: {
24 millisElapsed: 0.027259,
25 invocationCounts: { score: Long('25') }
26 }
27 }
28 },
29 collectors: {
30 allCollectorStats: {
31 millisElapsed: 0.112751,
32 invocationCounts: {
33 collect: Long('25'),
34 competitiveIterator: Long('4'),
35 setScorer: Long('4')
36 }
37 },
38 facet: { collectorStats: { millisElapsed: 0 } }
39 },
40 highlight: {
41 resolvedHighlightPaths: [ '$type:string/title' ],
42 stats: {
43 millisElapsed: 10.665238,
44 invocationCounts: {
45 executeHighlight: Long('1'),
46 setupHighlight: Long('1')
47 }
48 }
49 },
50 resultMaterialization: {
51 stats: {
52 millisElapsed: 3.548075,
53 invocationCounts: { retrieveAndSerialize: Long('1') }
54 }
55 },
56 metadata: {
57 mongotVersion: '1.43.1',
58 mongotHostName: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
59 indexName: 'default',
60 totalLuceneDocs: 21349
61 },
62 resourceUsage: {
63 majorFaults: Long('0'),
64 minorFaults: Long('0'),
65 userTimeMs: Long('10'),
66 systemTimeMs: Long('0'),
67 maxReportingThreads: 1,
68 numBatches: 1
69 }
70 },
71 requiresSearchMetaCursor: true
72 },
73 nReturned: Long('0'),
74 executionTimeMillisEstimate: Long('31')
75 },
76 {
77 '$_internalSearchIdLookup': {},
78 nReturned: Long('0'),
79 executionTimeMillisEstimate: Long('31')
80 },
81 {
82 '$project': {
83 description: true,
84 highlights: { '$meta': 'searchHighlights' },
85 _id: false
86 },
87 nReturned: Long('0'),
88 executionTimeMillisEstimate: Long('31')
89 }
90 ],
91 queryShapeHash: 'D08444272924C1E04A6E99D0CD4BF82FD929893862B3356F79EC18BBD1F0EF0C',
92 serverInfo: {
93 host: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
94 port: 27017,
95 version: '8.0.4',
96 gitVersion: 'bc35ab4305d9920d9d0491c1c9ef9b72383d31f9'
97 },
98 serverParameters: {
99 internalQueryFacetBufferSizeBytes: 104857600,
100 internalQueryFacetMaxOutputDocSizeBytes: 104857600,
101 internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
102 internalDocumentSourceGroupMaxMemoryBytes: 104857600,
103 internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
104 internalQueryProhibitBlockingMergeOnMongoS: 0,
105 internalQueryMaxAddToSetBytes: 104857600,
106 internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,
107 internalQueryFrameworkControl: 'trySbeRestricted',
108 internalQueryPlannerIgnoreIndexWithCollationForRegex: 1
109 },
110 command: {
111 aggregate: 'movies',
112 pipeline: [
113 {
114 '$search': {
115 text: { path: 'title', query: 'prince' },
116 highlight: { path: 'title', maxNumPassages: 1, maxCharsToExamine: 40 }
117 }
118 },
119 {
120 '$project': {
121 description: 1,
122 _id: 0,
123 highlights: { '$meta': 'searchHighlights' }
124 }
125 }
126 ],
127 cursor: {},
128 '$db': 'sample_mflix'
129 },
130 ok: 1,
131 '$clusterTime': {
132 clusterTime: Timestamp({ t: 1738081637, i: 1 }),
133 signature: {
134 hash: Binary.createFromBase64('TnFwebZsmrjLunk7/TN+9rfJ/8Y=', 0),
135 keyId: Long('7462787091647168517')
136 }
137 },
138 operationTime: Timestamp({ t: 1738081637, i: 1 })
139}
db.movies.explain("allPlansExecution").aggregate([
{
"$searchMeta": {
"facet": {
"operator": {
"near": {
"path": "released",
"origin": ISODate("1921-11-01T00:00:00.000+00:00"),
"pivot": 7776000000
}
},
"facets": {
"genresFacet": {
"type": "string",
"path": "genres"
},
"yearFacet" : {
"type" : "number",
"path" : "year",
"boundaries" : [1910,1920,1930,1940]
}
}
}
}
}
])
1{
2 explainVersion: '1',
3 stages: [
4 {
5 '$searchMeta': {
6 mongotQuery: {
7 facet: {
8 operator: {
9 near: {
10 path: 'released',
11 origin: ISODate('1921-11-01T00:00:00.000Z'),
12 pivot: 7776000000
13 }
14 },
15 facets: {
16 genresFacet: { type: 'string', path: 'genres' },
17 yearFacet: {
18 type: 'number',
19 path: 'year',
20 boundaries: [ 1910, 1920, 1930, 1940 ]
21 }
22 }
23 }
24 },
25 explain: {
26 query: {
27 type: 'LongDistanceFeatureQuery',
28 args: {},
29 stats: {
30 context: {
31 millisElapsed: 0.684076,
32 invocationCounts: { createWeight: Long('1'), createScorer: Long('12') }
33 },
34 match: {
35 millisElapsed: 1.285512,
36 invocationCounts: { nextDoc: Long('20884') }
37 },
38 score: {
39 millisElapsed: 1.321738,
40 invocationCounts: { score: Long('20878') }
41 }
42 }
43 },
44 collectors: {
45 allCollectorStats: {
46 millisElapsed: 10.536043,
47 invocationCounts: {
48 collect: Long('20878'),
49 competitiveIterator: Long('6'),
50 setScorer: Long('6')
51 }
52 },
53 facet: {
54 collectorStats: {
55 millisElapsed: 3.730834,
56 invocationCounts: { collect: Long('20878'), setScorer: Long('6') }
57 },
58 createCountsStats: {
59 millisElapsed: 10.350302,
60 invocationCounts: { generateFacetCounts: Long('2') }
61 },
62 stringFacetCardinalities: { genresFacet: { queried: 10, total: 25 } }
63 }
64 },
65 resultMaterialization: {
66 stats: {
67 millisElapsed: 10.645713,
68 invocationCounts: { retrieveAndSerialize: Long('1') }
69 }
70 },
71 metadata: {
72 mongotVersion: '1.43.1',
73 mongotHostName: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
74 indexName: 'default',
75 totalLuceneDocs: 21349
76 },
77 resourceUsage: {
78 majorFaults: Long('0'),
79 minorFaults: Long('0'),
80 userTimeMs: Long('10'),
81 systemTimeMs: Long('0'),
82 maxReportingThreads: 1,
83 numBatches: 1
84 }
85 },
86 requiresSearchMetaCursor: true
87 },
88 nReturned: Long('0'),
89 executionTimeMillisEstimate: Long('57')
90 }
91 ],
92 queryShapeHash: '582DB864C9BCFB96896CF1A3079CF70FAC10A9A1E19E8D66DF20A2BB40424FB5',
93 serverInfo: {
94 host: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
95 port: 27017,
96 version: '8.0.4',
97 gitVersion: 'bc35ab4305d9920d9d0491c1c9ef9b72383d31f9'
98 },
99 serverParameters: {
100 internalQueryFacetBufferSizeBytes: 104857600,
101 internalQueryFacetMaxOutputDocSizeBytes: 104857600,
102 internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
103 internalDocumentSourceGroupMaxMemoryBytes: 104857600,
104 internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
105 internalQueryProhibitBlockingMergeOnMongoS: 0,
106 internalQueryMaxAddToSetBytes: 104857600,
107 internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,
108 internalQueryFrameworkControl: 'trySbeRestricted',
109 internalQueryPlannerIgnoreIndexWithCollationForRegex: 1
110 },
111 command: {
112 aggregate: 'movies',
113 pipeline: [
114 {
115 '$searchMeta': {
116 facet: {
117 operator: {
118 near: {
119 path: 'released',
120 origin: ISODate('1921-11-01T00:00:00.000Z'),
121 pivot: 7776000000
122 }
123 },
124 facets: {
125 genresFacet: { type: 'string', path: 'genres' },
126 yearFacet: {
127 type: 'number',
128 path: 'year',
129 boundaries: [ 1910, 1920, 1930, 1940 ]
130 }
131 }
132 }
133 }
134 }
135 ],
136 cursor: {},
137 '$db': 'sample_mflix'
138 },
139 ok: 1,
140 '$clusterTime': {
141 clusterTime: Timestamp({ t: 1738081767, i: 1 }),
142 signature: {
143 hash: Binary.createFromBase64('ieRjqe84DdOnmlCcP3XBelo8vyM=', 0),
144 keyId: Long('7462787091647168517')
145 }
146 },
147 operationTime: Timestamp({ t: 1738081767, i: 1 })
148}

以下示例使用不同的操作符以 详细模式查询title queryPlanner字段。

db.movies.explain("queryPlanner").aggregate([
{
$search: {
"text": {
"path": "title",
"query": "yark",
"fuzzy": {
"maxEdits": 1,
"maxExpansions": 100,
}
}
}
}
])
1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "text" : {
7 "path" : "title",
8 "query" : "yark",
9 "fuzzy" : {
10 "maxEdits" : 1,
11 "maxExpansions" : 100
12 }
13 }
14 },
15 "explain" : {
16 "type" : "BooleanQuery",
17 "args" : {
18 "must" : [ ],
19 "mustNot" : [ ],
20 "should" : [
21 {
22 "type" : "BoostQuery",
23 "args" : {
24 "query" : {
25 "type" : "TermQuery",
26 "args" : {
27 "path" : "title",
28 "value" : "ark"
29 }
30 },
31 "boost" : 0.6666666269302368
32 }
33 },
34 {
35 "type" : "BoostQuery",
36 "args" : {
37 "query" : {
38 "type" : "TermQuery",
39 "args" : {
40 "path" : "title",
41 "value" : "yard"
42 }
43 },
44 "boost" : 0.75
45 }
46 },
47 {
48 "type" : "BoostQuery",
49 "args" : {
50 "query" : {
51 "type" : "TermQuery",
52 "args" : {
53 "path" : "title",
54 "value" : "mark"
55 }
56 },
57 "boost" : 0.75
58 }
59 },
60 {
61 "type" : "BoostQuery",
62 "args" : {
63 "query" : {
64 "type" : "TermQuery",
65 "args" : {
66 "path" : "title",
67 "value" : "park"
68 }
69 },
70 "boost" : 0.75
71 }
72 },
73 {
74 "type" : "BoostQuery",
75 "args" : {
76 "query" : {
77 "type" : "TermQuery",
78 "args" : {
79 "path" : "title",
80 "value" : "dark"
81 }
82 },
83 "boost" : 0.75
84 }
85 },
86 {
87 "type" : "BoostQuery",
88 "args" : {
89 "query" : {
90 "type" : "TermQuery",
91 "args" : {
92 "path" : "title",
93 "value" : "york"
94 }
95 },
96 "boost" : 0.75
97 }
98 }
99 ],
100 "filter" : [ ],
101 "minimumShouldMatch" : 0
102 }
103 }
104 }
105 },
106 {
107 "$_internalSearchIdLookup" : { }
108 }
109 ],
110 "serverInfo" : {
111 "host" : "atlas-example-shard-00-01.mongodb.net",
112 "port" : 27017,
113 "version" : "4.4.3",
114 "gitVersion" : "913d6b62acfbb344dde1b116f4161360acd8fd13"
115 },
116 "ok" : 1,
117 "$clusterTime" : {
118 "clusterTime" : Timestamp(1612457287, 1),
119 "signature" : {
120 "hash" : BinData(0,"kzn7hY7NOduVIqcfx+40ENKbMKQ="),
121 "keyId" : NumberLong("1234567890123456789")
122 }
123 },
124 "operationTime" : Timestamp(1612457287, 1)
125}
db.movies.explain("queryPlanner").aggregate([
{
$search: {
"text": {
"path": "title",
"query": "prince"
},
"highlight": {
"path": "title",
"maxNumPassages": 1,
"maxCharsToExamine": 40
}
}
},
{
$project: {
"description": 1,
"_id": 0,
"highlights": { "$meta": "searchHighlights" }
}
}
])
1{
2 explainVersion: '1',
3 stages: [
4 {
5 '$_internalSearchMongotRemote': {
6 mongotQuery: {
7 text: { path: 'title', query: 'prince' },
8 highlight: { path: 'title', maxNumPassages: 1, maxCharsToExamine: 40 }
9 },
10 explain: {
11 query: {
12 type: 'TermQuery',
13 args: { path: 'title', value: 'prince' }
14 },
15 highlight: { resolvedHighlightPaths: [ '$type:string/title' ] },
16 metadata: {
17 mongotVersion: '1.43.1',
18 mongotHostName: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
19 indexName: 'default',
20 totalLuceneDocs: 21349
21 }
22 },
23 requiresSearchMetaCursor: true
24 }
25 },
26 { '$_internalSearchIdLookup': {} },
27 {
28 '$project': {
29 description: true,
30 highlights: { '$meta': 'searchHighlights' },
31 _id: false
32 }
33 }
34 ],
35 queryShapeHash: 'D08444272924C1E04A6E99D0CD4BF82FD929893862B3356F79EC18BBD1F0EF0C',
36 serverInfo: {
37 host: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
38 port: 27017,
39 version: '8.0.4',
40 gitVersion: 'bc35ab4305d9920d9d0491c1c9ef9b72383d31f9'
41 },
42 serverParameters: {
43 internalQueryFacetBufferSizeBytes: 104857600,
44 internalQueryFacetMaxOutputDocSizeBytes: 104857600,
45 internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
46 internalDocumentSourceGroupMaxMemoryBytes: 104857600,
47 internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
48 internalQueryProhibitBlockingMergeOnMongoS: 0,
49 internalQueryMaxAddToSetBytes: 104857600,
50 internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,
51 internalQueryFrameworkControl: 'trySbeRestricted',
52 internalQueryPlannerIgnoreIndexWithCollationForRegex: 1
53 },
54 command: {
55 aggregate: 'movies',
56 pipeline: [
57 {
58 '$search': {
59 text: { path: 'title', query: 'prince' },
60 highlight: { path: 'title', maxNumPassages: 1, maxCharsToExamine: 40 }
61 }
62 },
63 {
64 '$project': {
65 description: 1,
66 _id: 0,
67 highlights: { '$meta': 'searchHighlights' }
68 }
69 }
70 ],
71 cursor: {},
72 '$db': 'sample_mflix'
73 },
74 ok: 1,
75 '$clusterTime': {
76 clusterTime: Timestamp({ t: 1738080637, i: 1 }),
77 signature: {
78 hash: Binary.createFromBase64('fIedxkRaoE5IWmIaN7/BsRC0AJc=', 0),
79 keyId: Long('7462787091647168517')
80 }
81 },
82 operationTime: Timestamp({ t: 1738080637, i: 1 })
83}
db.movies.explain("queryPlanner").aggregate([
{
"$searchMeta": {
"facet": {
"operator": {
"near": {
"path": "released",
"origin": ISODate("1921-11-01T00:00:00.000+00:00"),
"pivot": 7776000000
}
},
"facets": {
"genresFacet": {
"type": "string",
"path": "genres"
},
"yearFacet" : {
"type" : "number",
"path" : "year",
"boundaries" : [1910,1920,1930,1940]
}
}
}
}
}
])
1{
2 explainVersion: '1',
3 stages: [
4 {
5 '$searchMeta': {
6 mongotQuery: {
7 facet: {
8 operator: {
9 near: {
10 path: 'released',
11 origin: ISODate('1921-11-01T00:00:00.000Z'),
12 pivot: 7776000000
13 }
14 },
15 facets: {
16 genresFacet: { type: 'string', path: 'genres' },
17 yearFacet: {
18 type: 'number',
19 path: 'year',
20 boundaries: [ 1910, 1920, 1930, 1940 ]
21 }
22 }
23 }
24 },
25 explain: {
26 query: { type: 'LongDistanceFeatureQuery', args: {} },
27 collectors: {
28 facet: {
29 stringFacetCardinalities: { genresFacet: { queried: 10, total: 25 } }
30 }
31 },
32 metadata: {
33 mongotVersion: '1.43.1',
34 mongotHostName: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
35 indexName: 'default',
36 totalLuceneDocs: 21349
37 }
38 },
39 requiresSearchMetaCursor: true
40 }
41 }
42 ],
43 queryShapeHash: '582DB864C9BCFB96896CF1A3079CF70FAC10A9A1E19E8D66DF20A2BB40424FB5',
44 serverInfo: {
45 host: 'atlas-11decp-shard-00-02.2rnul.mongodb-dev.net',
46 port: 27017,
47 version: '8.0.4',
48 gitVersion: 'bc35ab4305d9920d9d0491c1c9ef9b72383d31f9'
49 },
50 serverParameters: {
51 internalQueryFacetBufferSizeBytes: 104857600,
52 internalQueryFacetMaxOutputDocSizeBytes: 104857600,
53 internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
54 internalDocumentSourceGroupMaxMemoryBytes: 104857600,
55 internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
56 internalQueryProhibitBlockingMergeOnMongoS: 0,
57 internalQueryMaxAddToSetBytes: 104857600,
58 internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,
59 internalQueryFrameworkControl: 'trySbeRestricted',
60 internalQueryPlannerIgnoreIndexWithCollationForRegex: 1
61 },
62 command: {
63 aggregate: 'movies',
64 pipeline: [
65 {
66 '$searchMeta': {
67 facet: {
68 operator: {
69 near: {
70 path: 'released',
71 origin: ISODate('1921-11-01T00:00:00.000Z'),
72 pivot: 7776000000
73 }
74 },
75 facets: {
76 genresFacet: { type: 'string', path: 'genres' },
77 yearFacet: {
78 type: 'number',
79 path: 'year',
80 boundaries: [ 1910, 1920, 1930, 1940 ]
81 }
82 }
83 }
84 }
85 }
86 ],
87 cursor: {},
88 '$db': 'sample_mflix'
89 },
90 ok: 1,
91 '$clusterTime': {
92 clusterTime: Timestamp({ t: 1738080797, i: 1 }),
93 signature: {
94 hash: Binary.createFromBase64('2E8qAEihttRWdJRyCTXRfA1es7I=', 0),
95 keyId: Long('7462787091647168517')
96 }
97 },
98 operationTime: Timestamp({ t: 1738080797, i: 1 })
99}

对于在管道中指定$limit阶段的查询, explain结果包括mongotDocsRequested指标,该指标显示mongodmongot请求的文档数。

例子

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

以下示例使用 autocomplete 操作符以 executionStats 详细程度模式查询 title 字段。

1db.movies.explain("executionStats").aggregate([
2 {
3 "$search": {
4 "autocomplete": {
5 "path": "title",
6 "query": "pre",
7 "fuzzy": {
8 "maxEdits": 1,
9 "prefixLength": 1,
10 "maxExpansions": 256
11 }
12 }
13 }
14 }
15])
1{
2 explainVersion: '1',
3 stages: [
4 {
5 '$_internalSearchMongotRemote': {
6 mongotQuery: {
7 autocomplete: {
8 path: 'title',
9 query: 'pre',
10 fuzzy: { maxEdits: 1, prefixLength: 1, maxExpansions: 256 }
11 }
12 },
13 explain: {
14 query: {
15 type: 'BooleanQuery',
16 args: {
17 must: [
18 {
19 type: 'MultiTermQueryConstantScoreBlendedWrapper',
20 args: {
21 queries: [
22 {
23 type: 'DefaultQuery',
24 args: { queryType: 'AutomatonQuery' },
25 stats: {
26 context: { millisElapsed: 0 },
27 match: { millisElapsed: 0 },
28 score: { millisElapsed: 0 }
29 }
30 }
31 ]
32 },
33 stats: {
34 context: {
35 millisElapsed: 34.187255,
36 invocationCounts: {
37 createWeight: Long('1'),
38 createScorer: Long('15')
39 }
40 },
41 match: {
42 millisElapsed: 1.077211,
43 invocationCounts: { nextDoc: Long('812') }
44 },
45 score: {
46 millisElapsed: 0.274761,
47 invocationCounts: { score: Long('807') }
48 }
49 }
50 }
51 ],
52 mustNot: [],
53 should: [
54 {
55 type: 'TermQuery',
56 args: { path: 'title', value: 'pre' },
57 stats: {
58 context: {
59 millisElapsed: 2.495506,
60 invocationCounts: {
61 createWeight: Long('1'),
62 createScorer: Long('5')
63 }
64 },
65 match: { millisElapsed: 0 },
66 score: { millisElapsed: 0 }
67 }
68 }
69 ],
70 filter: [],
71 minimumShouldMatch: 0
72 },
73 stats: {
74 context: {
75 millisElapsed: 43.795864,
76 invocationCounts: { createWeight: Long('1'), createScorer: Long('10') }
77 },
78 match: {
79 millisElapsed: 1.911068,
80 invocationCounts: { nextDoc: Long('812') }
81 },
82 score: {
83 millisElapsed: 0.982801,
84 invocationCounts: { score: Long('807') }
85 }
86 }
87 },
88 collectors: {
89 allCollectorStats: {
90 millisElapsed: 2.51114,
91 invocationCounts: {
92 collect: Long('807'),
93 competitiveIterator: Long('5'),
94 setScorer: Long('5')
95 }
96 },
97 facet: { collectorStats: { millisElapsed: 0 } }
98 },
99 resultMaterialization: {
100 stats: {
101 millisElapsed: 10.23124,
102 invocationCounts: { retrieveAndSerialize: Long('1') }
103 }
104 },
105 metadata: {
106 mongotVersion: '1.43.0',
107 mongotHostName: 'atlas-11decp-shard-00-01.2rnul.mongodb-dev.net',
108 indexName: 'default',
109 totalLuceneDocs: 21349
110 },
111 resourceUsage: {
112 majorFaults: Long('0'),
113 minorFaults: Long('145'),
114 userTimeMs: Long('30'),
115 systemTimeMs: Long('10'),
116 maxReportingThreads: 1,
117 numBatches: 1
118 }
119 },
120 requiresSearchMetaCursor: true
121 },
122 nReturned: Long('0'),
123 executionTimeMillisEstimate: Long('311')
124 },
125 {
126 '$_internalSearchIdLookup': {},
127 nReturned: Long('0'),
128 executionTimeMillisEstimate: Long('311')
129 }
130 ],
131 queryShapeHash: '6FD3791F785FA329D4ECD1171E0E5AF6772C18F5F0A7A50FC416D080A93C8CB7',
132 serverInfo: {
133 host: 'atlas-11decp-shard-00-01.2rnul.mongodb-dev.net',
134 port: 27017,
135 version: '8.0.4',
136 gitVersion: 'bc35ab4305d9920d9d0491c1c9ef9b72383d31f9'
137 },
138 serverParameters: {
139 internalQueryFacetBufferSizeBytes: 104857600,
140 internalQueryFacetMaxOutputDocSizeBytes: 104857600,
141 internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
142 internalDocumentSourceGroupMaxMemoryBytes: 104857600,
143 internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
144 internalQueryProhibitBlockingMergeOnMongoS: 0,
145 internalQueryMaxAddToSetBytes: 104857600,
146 internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,
147 internalQueryFrameworkControl: 'trySbeRestricted',
148 internalQueryPlannerIgnoreIndexWithCollationForRegex: 1
149 },
150 command: {
151 aggregate: 'movies',
152 pipeline: [
153 {
154 '$search': {
155 autocomplete: {
156 path: 'title',
157 query: 'pre',
158 fuzzy: { maxEdits: 1, prefixLength: 1, maxExpansions: 256 }
159 }
160 }
161 }
162 ],
163 cursor: {},
164 '$db': 'sample_mflix'
165 },
166 ok: 1,
167 '$clusterTime': {
168 clusterTime: Timestamp({ t: 1737671412, i: 10 }),
169 signature: {
170 hash: Binary.createFromBase64('a3CSqvS0rziAYQCk33WzTo/0Sow=', 0),
171 keyId: Long('7462787091647168517')
172 }
173 },
174 operationTime: Timestamp({ t: 1737671412, i: 10 })
175}

要学习;了解有关explain 响应元素的更多信息,请参阅解释结果。