Definition定义
db.collection.getSearchIndexes()
New in version 7.0.在版本7.0中新增。 (Also available starting in 6.0.7)
Returns information about existing MongoDB Search indexes or Vector Search indexes on a specified collection or view.返回指定集合或视图上现有MongoDB搜索索引或矢量搜索索引的信息。
Important
mongosh Method方法
This page documents a 本页记录了一种mongosh method. This is not the documentation for a language-specific driver, such as Node.js.mongosh方法。这不是针对特定语言驱动程序(如Node.js)的文档。
For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Important
This command is not supported in serverless instances. For more information, see Unsupported Commands.无服务器实例不支持此命令。有关详细信息,请参阅不支持的命令。
Syntax语法
Command syntax:命令语法:
db.<collection>.getSearchIndexes(<indexName>)Command Fields命令字段
getSearchIndexes() takes this field:接受此字段:
indexName | indexName field, getSearchIndexes() returns information about all MongoDB Search indexes on the collection.indexName字段,getSearchIndexes()将返回集合上所有MongoDB搜索索引的信息。 |
Access Control访问控制
If your deployment enforces access control, the user running 如果部署强制执行访问控制,则运行getSearchIndexes() must have the listSearchIndexes privilege action on the database or collection:getSearchIndexes()的用户必须对数据库或集合具有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输出
getSearchIndexes() returns an array of documents. Each document in the array contains the following fields:返回一组文档。数组中的每个文档都包含以下字段:
id | ||
name | ||
status | ||
queryable | ||
latestDefinitionVersion | ||
latestDefinitionVersion.version | ||
latestDefinitionVersion.createdAt | date | |
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 getSearchIndexes() output can be one of the following:getSearchIndexes()输出中的status字段可以是以下之一:
| Status | |
|---|---|
BUILDING |
|
DOES_NOT_EXIST |
|
DELETING |
|
FAILED |
|
PENDING |
|
READY |
|
STALE |
|
Examples示例
These examples demonstrate how to:这些示例演示了如何:
Return All Search Indexes返回所有搜索索引
The following example returns all MongoDB Search indexes on the 以下示例返回movies collection. The movies collection contains two search indexes: default and synonym_mappings.movies集合上的所有MongoDB搜索索引。movies集合包含两个搜索索引:default索引和synonym_mappings(同义词映射)。
db.movies.getSearchIndexes()
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返回单个搜索索引
The following example returns the 以下示例返回synonym_mappings index on the movies collection:movies集合上的synonym_mappings索引:
db.movies.getSearchIndexes("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
}
}
]
}
}
]
}
]