A Firestore query.
The query stages are executed in the following order: 1. from 2. where 3. select 4. orderBy + startAt + endAt 5. offset 6. limit
JSON representation |
---|
{ "select": { object ( |
Fields | |
---|---|
select |
Optional sub-set of the fields to return. This acts as a |
from[] |
The collections to query. |
where |
The filter to apply. |
orderBy[] |
The order to apply to the query results. Firestore allows callers to provide a full ordering, a partial ordering, or no ordering at all. In all cases, Firestore guarantees a stable ordering through the following rules:
Fields are appended with the same sort direction as the last order specified, or 'ASCENDING' if no order was specified. For example:
|
startAt |
A potential prefix of a position in the result set to start the query at. The ordering of the result set is based on the
This query's results are ordered by Cursors can reference either the full ordering or a prefix of the location, though it cannot reference more fields than what are in the provided Continuing off the example above, attaching the following start cursors will have varying impact:
Unlike Requires:
|
endAt |
A potential prefix of a position in the result set to end the query at. This is similar to Requires:
|
offset |
The number of documents to skip before returning the first result. This applies after the constraints specified by the Requires:
|
limit |
The maximum number of results to return. Applies after all other constraints. Requires:
|
findNearest |
Optional. A potential nearest neighbors search. Applies after all other filters and ordering. Finds the closest vector embeddings to the given query vector. |
Projection
The projection of document's fields to return.
JSON representation |
---|
{
"fields": [
{
object ( |
Fields | |
---|---|
fields[] |
The fields to return. If empty, all fields are returned. To only return the name of the document, use |
CollectionSelector
A selection of a collection, such as messages as m1
.
JSON representation |
---|
{ "collectionId": string, "allDescendants": boolean } |
Fields | |
---|---|
collectionId |
The collection ID. When set, selects only collections with this ID. |
allDescendants |
When false, selects only collections that are immediate children of the |
Filter
A filter.
JSON representation |
---|
{ // Union field |
Fields | |
---|---|
Union field filter_type . The type of filter. filter_type can be only one of the following: |
|
compositeFilter |
A composite filter. |
fieldFilter |
A filter on a document field. |
unaryFilter |
A filter that takes exactly one argument. |
CompositeFilter
A filter that merges multiple other filters using the given operator.
JSON representation |
---|
{ "op": enum ( |
Fields | |
---|---|
op |
The operator for combining multiple filters. |
filters[] |
The list of filters to combine. Requires:
|
Operator
A composite filter operator.
Enums | |
---|---|
OPERATOR_UNSPECIFIED |
Unspecified. This value must not be used. |
AND |
Documents are required to satisfy all of the combined filters. |
OR |
Documents are required to satisfy at least one of the combined filters. |
FieldFilter
A filter on a specific field.
JSON representation |
---|
{ "field": { object ( |
Fields | |
---|---|
field |
The field to filter by. |
op |
The operator to filter by. |
value |
The value to compare to. |
Operator
A field filter operator.
Enums | |
---|---|
OPERATOR_UNSPECIFIED |
Unspecified. This value must not be used. |
LESS_THAN |
The given Requires:
|
LESS_THAN_OR_EQUAL |
The given Requires:
|
GREATER_THAN |
The given Requires:
|
GREATER_THAN_OR_EQUAL |
The given Requires:
|
EQUAL |
The given field is equal to the given value . |
NOT_EQUAL |
The given Requires:
|
ARRAY_CONTAINS |
The given field is an array that contains the given value . |
IN |
The given Requires:
|
ARRAY_CONTAINS_ANY |
The given Requires:
|
NOT_IN |
The value of the Requires:
|
UnaryFilter
A filter with a single operand.
JSON representation |
---|
{ "op": enum ( |
Fields | |
---|---|
op |
The unary operator to apply. |
Union field operand_type . The argument to the filter. operand_type can be only one of the following: |
|
field |
The field to which to apply the operator. |
Operator
A unary operator.
Enums | |
---|---|
OPERATOR_UNSPECIFIED |
Unspecified. This value must not be used. |
IS_NAN |
The given field is equal to NaN . |
IS_NULL |
The given field is equal to NULL . |
IS_NOT_NAN |
The given Requires:
|
IS_NOT_NULL |
The given Requires:
|
Order
An order on a field.
JSON representation |
---|
{ "field": { object ( |
Fields | |
---|---|
field |
The field to order by. |
direction |
The direction to order by. Defaults to |
Direction
A sort direction.
Enums | |
---|---|
DIRECTION_UNSPECIFIED |
Unspecified. |
ASCENDING |
Ascending. |
DESCENDING |
Descending. |
FindNearest
Nearest Neighbors search config.
JSON representation |
---|
{ "vectorField": { object ( |
Fields | |
---|---|
vectorField |
Required. An indexed vector field to search upon. Only documents which contain vectors whose dimensionality match the queryVector can be returned. |
queryVector |
Required. The query vector that we are searching on. Must be a vector of no more than 2048 dimensions. |
distanceMeasure |
Required. The distance measure to use, required. |
limit |
Required. The number of nearest neighbors to return. Must be a positive integer of no more than 1000. |
DistanceMeasure
The distance measure to use when comparing vectors.
Enums | |
---|---|
DISTANCE_MEASURE_UNSPECIFIED |
Should not be set. |
EUCLIDEAN |
Measures the EUCLIDEAN distance between the vectors. See Euclidean to learn more |
COSINE |
Compares vectors based on the angle between them, which allows you to measure similarity that isn't based on the vectors magnitude. We recommend using DOT_PRODUCT with unit normalized vectors instead of COSINE distance, which is mathematically equivalent with better performance. See Cosine Similarity to learn more. |
DOT_PRODUCT |
Similar to cosine but is affected by the magnitude of the vectors. See Dot Product to learn more. |