Definition定义
$listSearchIndexes
New in version 7.0.在版本7.0中新增。 (Also available starting in 6.0.7)
Returns information about existing MongoDB Search indexes on a specified collection or view.返回指定集合或视图上现有MongoDB搜索索引的信息。
Important
This command can only be run on a deployment hosted on MongoDB Atlas.此命令只能在MongoDB Atlas上托管的部署上运行。
Syntax语法
Command syntax:命令语法:
db.<collection>.aggregate(
[
{
$listSearchIndexes:
{
id: <indexId>,
name: <indexName>
}
}
]
)Command Fields命令字段
$listSearchIndexes takes either of the following fields:接受以下字段之一:
id | |||
name |
You cannot specify both 不能同时指定id and name. If you omit both the id and name fields, $listSearchIndexes returns information about all MongoDB Search indexes on the collection.id和name。如果省略id和name字段,$listSearchIndexes将返回集合上所有MongoDB搜索索引的信息。
Access Control访问控制
If your deployment enforces access control, the user running 如果部署强制执行访问控制,则运行$listSearchIndexes must have the listSearchIndexes privilege action on the database or collection:$listSearchIndexes的用户必须对数据库或集合具有listSearchIndexes权限操作:
{
resource: {
db : <database>,
collection: <collection>
},
actions: [ "listSearchIndexes" ]
}
The built-in 内置的read role provides the the listSearchIndexes privilege. The following example grants the read role on the qa database:read角色提供listSearchIndexes权限。以下示例授予qa数据库上的read角色:
db.grantRolesToUser(
"<user>",
[ { role: "read", db: "qa" } ]
)Output输出
$listSearchIndexes returns an array of documents. Each document in the array contains the following fields:返回一组文档。数组中的每个文档都包含以下字段:
id | ||
name | ||
status | ||
queryable | ||
latestDefinitionVersion | ||
latestDefinitionVersion.version | ||
latestDefinitionVersion.createdAt | ||
latestDefinition | ||
statusDetail | mongot).mongot)上的索引状态。 | |
statusDetail.[n].hostname | mongot.mongot的主机名。 | |
statusDetail.[n].status | mongot.mongot的索引状态。 | |
statusDetail.[n].queryable | mongot.mongot上查询。 | |
statusDetail.[n].mainIndex |
| |
statusDetail.[n].stagedIndex |
| |
synonymMappingStatus |
| |
synonymMappingStatusDetail | mongot). This field (and its subfields) only appear if the index has synonyms defined.mongot)上索引同义词映射的状态。仅当索引定义了同义词时,才会显示此字段(及其子字段)。 | |
synonymMappingStatusDetail.[n].status | mongot processes.mongot进程中对应同义词映射的状态。 | |
synonymMappingStatusDetail.[n].queryable | mongot processes.mongot进程的查询。 | |
message | status for this synonym mapping is FAILED.status为FAILED(失败)时才会显示。 |
Index Status Details索引状态详细信息
The following table describes the embedded fields of the following documents:下表描述了以下文档的嵌入式字段: - statusDetail.[mongot].mainIndex - statusDetail.[mongot].stagedIndex
The fields describe the index status on a specific 这些字段描述了特定mongot.mongot的索引状态。
status | mongot.mongot。 | |
queryable | mongot.mongot上查询索引生成。 | |
synonymMappingStatus | mongot. Only present if the index has synonyms defined.mongot上的同义词映射的状态。仅当索引定义了同义词时才显示。 | |
synonymMappingStatusDetails |
| |
definitionVersion | ||
definitionVersion.version | mongot. When you update an index definition, the updated index builds with an incremented version number.mongot上使用的版本号。更新索引定义时,更新的索引将使用递增的版本号构建。 | |
definitionVersion.createdAt | date | |
definition |
Synonym Mapping Details同义词映射详细信息
The following table describes the embedded fields of the following objects:下表描述了以下对象的嵌入式字段:
statusDetail.mainIndex.synonymMappingStatusDetails.<synonymMapping>statusDetail.stagedIndex.synonymMappingStatusDetails<synonymMapping>
status | mongot process.mongot进程上同义词映射的状态。 | |
queryable | mongot process.mongot进程的查询。 | |
message | status for this synonym mapping is FAILED.status为FAILED(失败)时才会显示。 |
MongoDB Search Index StatusesMongoDB搜索索引状态
The status field in the $listSearchIndexes output can be one of the following:$listSearchIndexes输出中的status字段可以是以下之一:
| Status | |
|---|---|
BUILDING |
|
DOES_NOT_EXIST |
|
DELETING |
|
FAILED |
|
PENDING |
|
READY |
|
STALE |
|
Errors错误
Changed in version 7.1.在版本7.1中的更改。 This command throws an error when not executed on Atlas.此命令在Atlas上不执行时会抛出错误。
db.names.aggregate( [
{ $listSearchIndexes: { } }
] )
MongoServerError: PlanExecutor error during aggregation :: caused by :: Search index commands are only supported with Atlas.
In previous releases, this command returns an empty result when not executed on Atlas.在以前的版本中,此命令在Atlas上不执行时返回空结果。
Examples示例
MongoDB Shell
These examples demonstrate how to perform the following actions:这些示例演示了如何执行以下操作:
Return All Search Indexes返回所有搜索索引Return a Single Search Index by Name按名称返回单个搜索索引Return a Single Search Index by id按id返回单个搜索索引
Return All Search Indexes返回所有搜索索引
The following example returns all MongoDB Search indexes on the 以下示例返回movies collection:movies集合上的所有MongoDB搜索索引:
db.movies.aggregate(
[
{
$listSearchIndexes: { }
}
]
)
Sample output:样本输出:
[
{
id: '6524096020da840844a4c4a7',
name: 'default',
status: 'BUILDING',
queryable: true,
latestDefinitionVersion: {
version: 2,
createdAt: ISODate("2023-10-09T14:51:57.355Z")
},
latestDefinition: {
mappings: { dynamic: true },
storedSource: { include: [ 'awards.text' ] }
},
statusDetail: [
{
hostname: 'atlas-n1cm1j-shard-00-02',
status: 'BUILDING',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:08:32.000Z")
},
definition: { mappings: { dynamic: true, fields: {} } }
},
stagedIndex: {
status: 'PENDING',
queryable: false,
definitionVersion: {
version: 1,
createdAt: ISODate("2023-10-09T14:51:29.000Z")
},
definition: {
mappings: { dynamic: true, fields: {} },
storedSource: true
}
}
},
{
hostname: 'atlas-n1cm1j-shard-00-01',
status: 'BUILDING',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:08:32.000Z")
},
definition: { mappings: { dynamic: true, fields: {} } }
},
stagedIndex: {
status: 'PENDING',
queryable: false,
definitionVersion: {
version: 1,
createdAt: ISODate("2023-10-09T14:51:29.000Z")
},
definition: {
mappings: { dynamic: true, fields: {} },
storedSource: true
}
}
},
{
hostname: 'atlas-n1cm1j-shard-00-00',
status: 'BUILDING',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:08:32.000Z")
},
definition: { mappings: { dynamic: true, fields: {} } }
}
}
]
},
{
id: '65240be420da840844a4d077',
name: 'synonym_mappings',
status: 'READY',
queryable: true,
latestDefinitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.305Z")
},
latestDefinition: {
mappings: {
dynamic: true,
fields: {
fullplot: { type: 'string' }
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
],
statusDetail: [
{
hostname: 'atlas-n1cm1j-shard-00-02',
status: 'READY',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.000Z")
},
definition: {
mappings: {
dynamic: true,
fields: {
fullplot: {
type: 'string',
indexOptions: 'offsets',
store: true,
norms: 'include'
}
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
]
}
},
{
hostname: 'atlas-n1cm1j-shard-00-01',
status: 'READY',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.000Z")
},
definition: {
mappings: {
dynamic: true,
fields: {
fullplot: {
type: 'string',
indexOptions: 'offsets',
store: true,
norms: 'include'
}
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
]
}
},
{
hostname: 'atlas-n1cm1j-shard-00-00',
status: 'READY',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.000Z")
},
definition: {
mappings: {
dynamic: true,
fields: {
fullplot: {
type: 'string',
indexOptions: 'offsets',
store: true,
norms: 'include'
}
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
]
}
}
]
}
]Return a Single Search Index by Name按名称返回单个搜索索引
The following example returns the index named 以下示例返回synonym-mappings on the movies collection:movies集合上名为synonym-mappings(同义词映射)的索引:
db.movies.aggregate(
[
{
$listSearchIndexes:
{
name: "synonym-mappings"
}
}
]
)
Sample output:样本输出:
[
{
id: '65240be420da840844a4d077',
name: 'synonym_mappings',
status: 'READY',
queryable: true,
latestDefinitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.305Z")
},
latestDefinition: {
mappings: {
dynamic: true,
fields: {
fullplot: { type: 'string' }
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
],
statusDetail: [
{
hostname: 'atlas-n1cm1j-shard-00-02',
status: 'READY',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.000Z")
},
definition: {
mappings: {
dynamic: true,
fields: {
fullplot: {
type: 'string',
indexOptions: 'offsets',
store: true,
norms: 'include'
}
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
]
}
},
{
hostname: 'atlas-n1cm1j-shard-00-01',
status: 'READY',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.000Z")
},
definition: {
mappings: {
dynamic: true,
fields: {
fullplot: {
type: 'string',
indexOptions: 'offsets',
store: true,
norms: 'include'
}
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
]
}
},
{
hostname: 'atlas-n1cm1j-shard-00-00',
status: 'READY',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:19:16.000Z")
},
definition: {
mappings: {
dynamic: true,
fields: {
fullplot: {
type: 'string',
indexOptions: 'offsets',
store: true,
norms: 'include'
}
}
},
synonyms: [
{
name: 'synonym_mapping',
analyzer: 'lucene.english',
source: { collection: 'synonyms' }
}
]
},
synonymMappingStatus: 'READY',
synonymMappingStatusDetail: [
{
synonym_mapping: {
status: 'READY',
queryable: true
}
}
]
}
}
]
}
]Return a Single Search Index by id按id返回单个搜索索引
The following example returns the search index with the provided 以下示例返回具有提供的id value:id值的搜索索引:
db.movies.aggregate(
[
{
$listSearchIndexes:
{
id: "6524096020da840844a4c4a7"
}
}
]
)
Sample output:样本输出:
[
{
id: '6524096020da840844a4c4a7',
name: 'default',
status: 'BUILDING',
queryable: true,
latestDefinitionVersion: {
version: 2,
createdAt: ISODate("2023-10-09T14:51:57.355Z")
},
latestDefinition: {
mappings: { dynamic: true },
storedSource: { include: [ 'awards.text' ] }
},
statusDetail: [
{
hostname: 'atlas-n1cm1j-shard-00-02',
status: 'BUILDING',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:08:32.000Z")
},
definition: { mappings: { dynamic: true, fields: {} } }
},
stagedIndex: {
status: 'PENDING',
queryable: false,
definitionVersion: {
version: 1,
createdAt: ISODate("2023-10-09T14:51:29.000Z")
},
definition: {
mappings: { dynamic: true, fields: {} },
storedSource: true
}
}
},
{
hostname: 'atlas-n1cm1j-shard-00-01',
status: 'BUILDING',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:08:32.000Z")
},
definition: { mappings: { dynamic: true, fields: {} } }
},
stagedIndex: {
status: 'PENDING',
queryable: false,
definitionVersion: {
version: 1,
createdAt: ISODate("2023-10-09T14:51:29.000Z")
},
definition: {
mappings: { dynamic: true, fields: {} },
storedSource: true
}
}
},
{
hostname: 'atlas-n1cm1j-shard-00-00',
status: 'BUILDING',
queryable: true,
mainIndex: {
status: 'READY',
queryable: true,
definitionVersion: {
version: 0,
createdAt: ISODate("2023-10-09T14:08:32.000Z")
},
definition: { mappings: { dynamic: true, fields: {} } }
}
}
]
}
]Node.js
To use the MongoDB Node.js driver to add a 要使用MongoDB Node.js驱动程序将$listSearchIndexes stage to an aggregation pipeline, use the $listSearchIndexes operator in a pipeline object.$listSearchIndexes阶段添加到聚合管道中,请在管道对象中使用$listSearchIndexes运算符。
Note
The Node.js driver provides a helper method, listSearchIndexes(), that performs the same operation as the Node.js驱动程序提供了一个辅助方法$listSearchIndexes pipeline stage. listSearchIndexes(),它执行与$listSearchIndexs管道阶段相同的操作。To learn more, see the Indexes page in the MongoDB Node.js driver documentation.要了解更多信息,请参阅MongoDB Node.js驱动程序文档中的索引页面。
Return All Search Indexes返回所有搜索索引
The following example returns all MongoDB Search indexes on a collection:以下示例返回集合上的所有MongoDB搜索索引:
const pipeline = [{ $listSearchIndexes: {} }];
const cursor = collection.aggregate(pipeline);
return cursor;Return a Single Search Index by Name按名称返回单个搜索索引
The following example returns the index named 以下示例返回名为synonym-mappings:synonym-mappings(同义词映射)的索引:
const pipeline = [{ $listSearchIndexes: { name: "synonym-mappings" } }];
const cursor = collection.aggregate(pipeline);
return cursor;Return a Single Search Index by id按id返回单个搜索索引
The following example returns the search index with the provided 以下示例返回具有提供的id value:id值的搜索索引:
const pipeline = [{ $listSearchIndexes: { id: "6524096020da840844a4c4a7" } }];
const cursor = collection.aggregate(pipeline);
return cursor;Learn More了解更多
To use a 要使用mongosh method to view MongoDB Search indexes, see db.collection.getSearchIndexes().mongosh方法查看MongoDB搜索索引,请参阅db.collection.getSearchIndexes()。
To create MongoDB Search indexes, see:要创建MongoDB搜索索引,请参阅:
Thedb.collection.createSearchIndex()mongoshmethod方法ThecreateSearchIndexesdatabase command数据库命令