db.collection.getSearchIndexes()
Nesta página
Definição
Novidade na versão 6.0.7.
Retorna informações sobre Atlas Search indexes em uma coleção especificada.
Importante
Método mongosh
Esta página documenta um método mongosh
. Esta não é a documentação para um driver específico de idioma, como Node.js.
Para drivers de API do MongoDB, consulte a documentação do driver do MongoDB específica da linguagem.
Compatibilidade
Esse método está disponível em implantações hospedadas nos seguintes ambientes:
MongoDB Atlas: o serviço totalmente gerenciado para implantações do MongoDB na nuvem
Importante
Este comando não é suportado em instâncias sem servidor. Para obter mais informações, consulte Comandos não suportados.
Sintaxe
Sintaxe do comando:
db.<collection>.getSearchIndexes(<indexName>)
Campos de comando
getSearchIndexes()
takes this field:
Campo | Tipo | necessidade | Descrição |
---|---|---|---|
| string | Opcional | Name of the index to return information about. If you omit the
|
Controle de acesso
Se sua implantação impor controle de acesso, o usuário que executa getSearchIndexes()
deverá ter a ação de privilégio listSearchIndexes
no banco de dados ou na coleção:
{ 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:
db.grantRolesToUser( "<user>", [ { role: "read", db: "qa" } ] )
Saída
getSearchIndexes()
returns an array of documents. Each document in the array
contains the following fields:
Campo | Tipo | Descrição |
---|---|---|
| string | Unique identifier for the index. |
| string | Name of the index. |
| string | Status of the index. For more information, see Atlas Search Index Statuses. |
| booleano | Indicates whether the index is ready to be queried. |
| documento | Describes the version of the index. |
| inteiro | Version number associated with the index definition. When you update an index definition, the version number increments automatically. |
| data | Time when the current index definition was created. |
| documento | The most recent definition for the index. For more information, see Sintaxe de definição do índice de pesquisar. |
| matriz de documentos | Contains the status of the index on each search host
( |
| string | Hostname of the corresponding |
| string | Status of the index on the corresponding |
| booleano | Indicates whether the index is ready to be queried on the
corresponding |
| documento | Contains status information about the active index on the
corresponding For details, see Index Status Details. |
| documento | Contains status information about an index being built in the
background on the corresponding For details, see Index Status Details. |
| string | Status of the index's synonym mappings. This field only appears if the index has synonyms defined. Can be one of the following values:
The returned status is a summary of the synonym mappings on each
individual |
| matriz de documentos | Contains the status of the index's synonym mappings on each
search host ( |
| string | Status for the corresponding synonym mapping across all
|
| booleano | Indicates whether the corresponding synonym mapping can support
queries across all |
| string | Describes an error for the synonym mapping, if applicable. Only
appears if the |
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
.
Campo | Tipo | Descrição |
---|---|---|
| string | The state of the index generation on the corresponding
|
| booleano | Indicates whether the index generation is ready to be queried on
the corresponding |
| string | The state of the index generation's synonym mappings on the
corresponding |
| documento | Contains the status of the index's synonym mappings on the
corresponding For more information, see Synonym Mapping Details. |
| documento | Describes the index definition version that this index generation is being built with. |
| inteiro | Version number that the index generation is using on the
corresponding |
| data | Time when the index definition was created. |
| documento | The definition that this index is being built with. |
Synonym Mapping Details
The following table describes the embedded fields of the following objects:
statusDetail.mainIndex.synonymMappingStatusDetails.<synonymMapping>
statusDetail.stagedIndex.synonymMappingStatusDetails<synonymMapping>
Campo | Tipo | Descrição |
---|---|---|
| string | Status for the synonym mapping across on the corresponding
|
| booleano | Indicates whether the synonym mapping can support queries on the
corresponding |
| string | Describes an error for the synonym mapping, if applicable. Only
appears if the |
Atlas Search Index Statuses
The status
field in the getSearchIndexes()
output can be one of the
following:
Status | Descrição |
---|---|
| The following scenarios can cause an index to be in the
When the index is in the
An index in the |
| The index does not exist. An index in the |
| Atlas is deleting the index. An index in the |
| The index build failed. Indexes can enter the An index in the |
| Atlas has not yet started building the index. An index in the |
| The index is ready and can support queries. An index in the |
| The index is queryable but has stopped replicating data from the indexed collection. Searches on the index may return out-of-date data. Indexes can enter the An index in the |
Exemplos
These examples demonstrate how to:
Return All Search Indexes
The following example returns all Atlas Search indexes on the movies
collection. The movies
collection contains two search indexes:
default
and 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:
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 } } ] } } ] } ]