xref: /aosp_15_r20/external/googleapis/google/firestore/admin/v1/index.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.firestore.admin.v1;
18
19import "google/api/field_behavior.proto";
20import "google/api/resource.proto";
21
22option csharp_namespace = "Google.Cloud.Firestore.Admin.V1";
23option go_package = "cloud.google.com/go/firestore/apiv1/admin/adminpb;adminpb";
24option java_multiple_files = true;
25option java_outer_classname = "IndexProto";
26option java_package = "com.google.firestore.admin.v1";
27option objc_class_prefix = "GCFS";
28option php_namespace = "Google\\Cloud\\Firestore\\Admin\\V1";
29option ruby_package = "Google::Cloud::Firestore::Admin::V1";
30
31// Cloud Firestore indexes enable simple and complex queries against
32// documents in a database.
33message Index {
34  option (google.api.resource) = {
35    type: "firestore.googleapis.com/Index"
36    pattern: "projects/{project}/databases/{database}/collectionGroups/{collection}/indexes/{index}"
37  };
38
39  // Query Scope defines the scope at which a query is run. This is specified on
40  // a StructuredQuery's `from` field.
41  enum QueryScope {
42    // The query scope is unspecified. Not a valid option.
43    QUERY_SCOPE_UNSPECIFIED = 0;
44
45    // Indexes with a collection query scope specified allow queries
46    // against a collection that is the child of a specific document, specified
47    // at query time, and that has the collection id specified by the index.
48    COLLECTION = 1;
49
50    // Indexes with a collection group query scope specified allow queries
51    // against all collections that has the collection id specified by the
52    // index.
53    COLLECTION_GROUP = 2;
54
55    // Include all the collections's ancestor in the index. Only available for
56    // Datastore Mode databases.
57    COLLECTION_RECURSIVE = 3;
58  }
59
60  // API Scope defines the APIs (Firestore Native, or Firestore in
61  // Datastore Mode) that are supported for queries.
62  enum ApiScope {
63    // The index can only be used by the Firestore Native query API.
64    // This is the default.
65    ANY_API = 0;
66
67    // The index can only be used by the Firestore in Datastore Mode query API.
68    DATASTORE_MODE_API = 1;
69  }
70
71  // A field in an index.
72  // The field_path describes which field is indexed, the value_mode describes
73  // how the field value is indexed.
74  message IndexField {
75    // The supported orderings.
76    enum Order {
77      // The ordering is unspecified. Not a valid option.
78      ORDER_UNSPECIFIED = 0;
79
80      // The field is ordered by ascending field value.
81      ASCENDING = 1;
82
83      // The field is ordered by descending field value.
84      DESCENDING = 2;
85    }
86
87    // The supported array value configurations.
88    enum ArrayConfig {
89      // The index does not support additional array queries.
90      ARRAY_CONFIG_UNSPECIFIED = 0;
91
92      // The index supports array containment queries.
93      CONTAINS = 1;
94    }
95
96    // The index configuration to support vector search operations
97    message VectorConfig {
98      // An index that stores vectors in a flat data structure, and supports
99      // exhaustive search.
100      message FlatIndex {}
101
102      // Required. The vector dimension this configuration applies to.
103      //
104      // The resulting index will only include vectors of this dimension, and
105      // can be used for vector search with the same dimension.
106      int32 dimension = 1 [(google.api.field_behavior) = REQUIRED];
107
108      // The type of index used.
109      oneof type {
110        // Indicates the vector index is a flat index.
111        FlatIndex flat = 2;
112      }
113    }
114
115    // Can be __name__.
116    // For single field indexes, this must match the name of the field or may
117    // be omitted.
118    string field_path = 1;
119
120    // How the field value is indexed.
121    oneof value_mode {
122      // Indicates that this field supports ordering by the specified order or
123      // comparing using =, !=, <, <=, >, >=.
124      Order order = 2;
125
126      // Indicates that this field supports operations on `array_value`s.
127      ArrayConfig array_config = 3;
128
129      // Indicates that this field supports nearest neighbors and distance
130      // operations on vector.
131      VectorConfig vector_config = 4;
132    }
133  }
134
135  // The state of an index. During index creation, an index will be in the
136  // `CREATING` state. If the index is created successfully, it will transition
137  // to the `READY` state. If the index creation encounters a problem, the index
138  // will transition to the `NEEDS_REPAIR` state.
139  enum State {
140    // The state is unspecified.
141    STATE_UNSPECIFIED = 0;
142
143    // The index is being created.
144    // There is an active long-running operation for the index.
145    // The index is updated when writing a document.
146    // Some index data may exist.
147    CREATING = 1;
148
149    // The index is ready to be used.
150    // The index is updated when writing a document.
151    // The index is fully populated from all stored documents it applies to.
152    READY = 2;
153
154    // The index was being created, but something went wrong.
155    // There is no active long-running operation for the index,
156    // and the most recently finished long-running operation failed.
157    // The index is not updated when writing a document.
158    // Some index data may exist.
159    // Use the google.longrunning.Operations API to determine why the operation
160    // that last attempted to create this index failed, then re-create the
161    // index.
162    NEEDS_REPAIR = 3;
163  }
164
165  // Output only. A server defined name for this index.
166  // The form of this name for composite indexes will be:
167  // `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{composite_index_id}`
168  // For single field indexes, this field will be empty.
169  string name = 1;
170
171  // Indexes with a collection query scope specified allow queries
172  // against a collection that is the child of a specific document, specified at
173  // query time, and that has the same collection id.
174  //
175  // Indexes with a collection group query scope specified allow queries against
176  // all collections descended from a specific document, specified at query
177  // time, and that have the same collection id as this index.
178  QueryScope query_scope = 2;
179
180  // The API scope supported by this index.
181  ApiScope api_scope = 5;
182
183  // The fields supported by this index.
184  //
185  // For composite indexes, this requires a minimum of 2 and a maximum of 100
186  // fields. The last field entry is always for the field path `__name__`. If,
187  // on creation, `__name__` was not specified as the last field, it will be
188  // added automatically with the same direction as that of the last field
189  // defined. If the final field in a composite index is not directional, the
190  // `__name__` will be ordered ASCENDING (unless explicitly specified).
191  //
192  // For single field indexes, this will always be exactly one entry with a
193  // field path equal to the field path of the associated field.
194  repeated IndexField fields = 3;
195
196  // Output only. The serving state of the index.
197  State state = 4;
198}
199