Skip to main content

indexes

Creates, updates, deletes, gets or lists an indexes resource.

Overview

Nameindexes
TypeResource
Idgoogle.firestore.indexes

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringOutput only. A server defined name for this index. The form of this name for composite indexes will be: projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{composite_index_id} For single field indexes, this field will be empty.
apiScopestringThe API scope supported by this index.
densitystringImmutable. The density configuration of the index.
fieldsarrayThe fields supported by this index. For composite indexes, this requires a minimum of 2 and a maximum of 100 fields. The last field entry is always for the field path __name__. If, on creation, __name__ was not specified as the last field, it will be added automatically with the same direction as that of the last field defined. If the final field in a composite index is not directional, the __name__ will be ordered ASCENDING (unless explicitly specified). For single field indexes, this will always be exactly one entry with a field path equal to the field path of the associated field.
multikeybooleanOptional. Whether the index is multikey. By default, the index is not multikey. For non-multikey indexes, none of the paths in the index definition reach or traverse an array, except via an explicit array index. For multikey indexes, at most one of the paths in the index definition reach or traverse an array, except via an explicit array index. Violations will result in errors. Note this field only applies to index with MONGODB_COMPATIBLE_API ApiScope.
queryScopestringIndexes with a collection query scope specified allow queries against a collection that is the child of a specific document, specified at query time, and that has the same collection ID. Indexes with a collection group query scope specified allow queries against all collections descended from a specific document, specified at query time, and that have the same collection ID as this index.
shardCountinteger (int32)Optional. The number of shards for the index.
statestringOutput only. The serving state of the index.
uniquebooleanOptional. Whether it is an unique index. Unique index ensures all values for the indexed field(s) are unique across documents.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectprojectsId, databasesId, collectionGroupsId, indexesIdGets a composite index.
listselectprojectsId, databasesId, collectionGroupsIdfilter, pageSize, pageTokenLists composite indexes.
createinsertprojectsId, databasesId, collectionGroupsIdCreates a composite index. This returns a google.longrunning.Operation which may be used to track the status of the creation. The metadata for the operation will be the type IndexOperationMetadata.
deletedeleteprojectsId, databasesId, collectionGroupsId, indexesIdDeletes a composite index.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
collectionGroupsIdstring
databasesIdstring
indexesIdstring
projectsIdstring
filterstring
pageSizeinteger (int32)
pageTokenstring

SELECT examples

Gets a composite index.

SELECT
name,
apiScope,
density,
fields,
multikey,
queryScope,
shardCount,
state,
unique
FROM google.firestore.indexes
WHERE projectsId = '{{ projectsId }}' -- required
AND databasesId = '{{ databasesId }}' -- required
AND collectionGroupsId = '{{ collectionGroupsId }}' -- required
AND indexesId = '{{ indexesId }}' -- required;

INSERT examples

Creates a composite index. This returns a google.longrunning.Operation which may be used to track the status of the creation. The metadata for the operation will be the type IndexOperationMetadata.

INSERT INTO google.firestore.indexes (
data__name,
data__queryScope,
data__apiScope,
data__fields,
data__state,
data__density,
data__multikey,
data__shardCount,
data__unique,
projectsId,
databasesId,
collectionGroupsId
)
SELECT
'{{ name }}',
'{{ queryScope }}',
'{{ apiScope }}',
'{{ fields }}',
'{{ state }}',
'{{ density }}',
{{ multikey }},
{{ shardCount }},
{{ unique }},
'{{ projectsId }}',
'{{ databasesId }}',
'{{ collectionGroupsId }}'
RETURNING
name,
done,
error,
metadata,
response
;

DELETE examples

Deletes a composite index.

DELETE FROM google.firestore.indexes
WHERE projectsId = '{{ projectsId }}' --required
AND databasesId = '{{ databasesId }}' --required
AND collectionGroupsId = '{{ collectionGroupsId }}' --required
AND indexesId = '{{ indexesId }}' --required;