---
title: "POST /v1/projects/{projectId}:runQuery"
method: POST
path: "/v1/projects/{projectId}:runQuery"
tags: ["projects"]
---

# POST /v1/projects/{projectId}:runQuery

`POST /v1/projects/{projectId}:runQuery`

Queries for entities.

## Path parameters

- `projectId` string, required

## Request body

- RunQueryRequest — The request for Datastore.RunQuery.
  - `databaseId` string — The ID of the database against which to make the request. '(default)' is not allowed; please use empty string '' to refer the default database.
  - `readOptions` ReadOptions — The options shared by read requests.
    - `readTime` string, google-datetime — Reads entities as they were at the given time. This value is only supported for Cloud Firestore in Datastore mode. This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.
    - `newTransaction` TransactionOptions — Options for beginning a new transaction. Transactions can be created explicitly with calls to Datastore.BeginTransaction or implicitly by setting ReadOptions.new_transaction in read requests.
      - `readWrite` ReadWrite — Options specific to read / write transactions.
        - `previousTransaction` string, byte — The transaction identifier of the transaction being retried.
      - `readOnly` ReadOnly — Options specific to read-only transactions.
        - `readTime` string, google-datetime — Reads entities at the given time. This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.
    - `readConsistency` 'READ_CONSISTENCY_UNSPECIFIED' | 'STRONG' | 'EVENTUAL' — The non-transactional read consistency to use.
    - `transaction` string, byte — The identifier of the transaction in which to read. A transaction identifier is returned by a call to Datastore.BeginTransaction.
  - `partitionId` PartitionId — A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `""`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\d\.\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.
    - `projectId` string — The ID of the project to which the entities belong.
    - `databaseId` string — If not empty, the ID of the database to which the entities belong.
    - `namespaceId` string — If not empty, the ID of the namespace to which the entities belong.
  - `gqlQuery` GqlQuery — A [GQL query](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
    - `allowLiterals` boolean — When false, the query string must not contain any literals and instead must bind all values. For example, `SELECT * FROM Kind WHERE a = 'string literal'` is not allowed, while `SELECT * FROM Kind WHERE a = @value` is.
    - `namedBindings` object — For each non-reserved named binding site in the query string, there must be a named parameter with that name, but not necessarily the inverse. Key must match regex `A-Za-z_$*`, must not match regex `__.*__`, and must not be `""`.
    - `queryString` string — A string of the format described [here](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
    - `positionalBindings` GqlQueryParameter[] — Numbered binding site @1 references the first numbered parameter, effectively using 1-based indexing, rather than the usual 0. For each binding site numbered i in `query_string`, there must be an i-th numbered parameter. The inverse must also be true.
      - `value` Value — A message that can hold any of the supported value types and associated metadata.
        - `booleanValue` boolean — A boolean value.
        - `arrayValue` ArrayValue — An array value.
          - `values` Value[] — Values in the array. The order of values in an array is preserved as long as all values have identical settings for 'exclude_from_indexes'.
        - `meaning` integer — The `meaning` field should only be populated for backwards compatibility.
        - `keyValue` Key — A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.
          - `partitionId` PartitionId — A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `""`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\d\.\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.
            - `projectId` string — The ID of the project to which the entities belong.
            - `databaseId` string — If not empty, the ID of the database to which the entities belong.
            - `namespaceId` string — If not empty, the ID of the namespace to which the entities belong.
          - `path` PathElement[] — The entity path. An entity path consists of one or more elements composed of a kind and a string or numerical identifier, which identify entities. The first element identifies a _root entity_, the second element identifies a _child_ of the root entity, the third element identifies a child of the second entity, and so forth. The entities identified by all prefixes of the path are called the element's _ancestors_. An entity path is always fully complete: *all* of the entity's ancestors are required to be in the path along with the entity identifier itself. The only exception is that in some documented cases, the identifier in the last path element (for the entity) itself may be omitted. For example, the last path element of the key of `Mutation.insert` may have no identifier. A path can never be empty, and a path can have at most 100 elements.
            - `name` string — The name of the entity. A name matching regex `__.*__` is reserved/read-only. A name must not be more than 1500 bytes when UTF-8 encoded. Cannot be `""`. Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are encoded as `__bytes__` where `` is the base-64 encoding of the bytes.
            - `kind` string — The kind of the entity. A kind matching regex `__.*__` is reserved/read-only. A kind must not contain more than 1500 bytes when UTF-8 encoded. Cannot be `""`. Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are encoded as `__bytes__` where `` is the base-64 encoding of the bytes.
            - `id` string, int64 — The auto-allocated ID of the entity. Never equal to zero. Values less than zero are discouraged and may not be supported in the future.
        - `nullValue` 'NULL_VALUE' — A null value.
        - `geoPointValue` LatLng — An object that represents a latitude/longitude pair. This is expressed as a pair of doubles to represent degrees latitude and degrees longitude. Unless specified otherwise, this object must conform to the WGS84 standard. Values must be within normalized ranges.
          - `longitude` number, double — The longitude in degrees. It must be in the range [-180.0, +180.0].
          - `latitude` number, double — The latitude in degrees. It must be in the range [-90.0, +90.0].
        - `doubleValue` number, double — A double value.
        - `entityValue` Entity — A Datastore data object. Must not exceed 1 MiB - 4 bytes.
          - `properties` object — The entity's properties. The map's keys are property names. A property name matching regex `__.*__` is reserved. A reserved property name is forbidden in certain documented contexts. The map keys, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty.
          - `key` Key — A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.
            - `partitionId` PartitionId — A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `""`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\d\.\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.
              - …
            - `path` PathElement[] — The entity path. An entity path consists of one or more elements composed of a kind and a string or numerical identifier, which identify entities. The first element identifies a _root entity_, the second element identifies a _child_ of the root entity, the third element identifies a child of the second entity, and so forth. The entities identified by all prefixes of the path are called the element's _ancestors_. An entity path is always fully complete: *all* of the entity's ancestors are required to be in the path along with the entity identifier itself. The only exception is that in some documented cases, the identifier in the last path element (for the entity) itself may be omitted. For example, the last path element of the key of `Mutation.insert` may have no identifier. A path can never be empty, and a path can have at most 100 elements.
              - …
        - `stringValue` string — A UTF-8 encoded string value. When `exclude_from_indexes` is false (it is indexed) , may have at most 1500 bytes. Otherwise, may be set to at most 1,000,000 bytes.
        - `blobValue` string, byte — A blob value. May have at most 1,000,000 bytes. When `exclude_from_indexes` is false, may have at most 1500 bytes. In JSON requests, must be base64-encoded.
        - `timestampValue` string, google-datetime — A timestamp value. When stored in the Datastore, precise only to microseconds; any additional precision is rounded down.
        - `excludeFromIndexes` boolean — If the value should be excluded from all indexes including those defined explicitly.
        - `integerValue` string, int64 — An integer value.
      - `cursor` string, byte — A query cursor. Query cursors are returned in query result batches.
  - `explainOptions` ExplainOptions — Explain options for the query.
    - `analyze` boolean — Optional. Whether to execute this query. When false (the default), the query will be planned, returning only metrics from the planning stages. When true, the query will be planned and executed, returning the full query results along with both planning and execution stage metrics.
  - `propertyMask` PropertyMask — The set of arbitrarily nested property paths used to restrict an operation to only a subset of properties in an entity.
    - `paths` string[] — The paths to the properties covered by this mask. A path is a list of property names separated by dots (`.`), for example `foo.bar` means the property `bar` inside the entity property `foo` inside the entity associated with this path. If a property name contains a dot `.` or a backslash `\`, then that name must be escaped. A path must not be empty, and may not reference a value inside an array value.
  - `requestOptions` RequestOptions — Options for a request.
    - `requestTags` string[] — Optional. The request tags for the request. The tags are processed as follows: - Truncated to 510 characters. - Filtered out if empty. - Deduplicated. - Limited to 50 tags.
  - `query` Query — A query for entities. The query stages are executed in the following order: 1. kind 2. filter 3. projection 4. order + start_cursor + end_cursor 5. offset 6. limit 7. find_nearest
    - `startCursor` string, byte — A starting point for the query results. Query cursors are returned in query result batches and [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
    - `endCursor` string, byte — An ending point for the query results. Query cursors are returned in query result batches and [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
    - `distinctOn` PropertyReference[] — The properties to make distinct. The query results will contain the first result for each distinct combination of values for the given properties (if empty, all results are returned). Requires: * If `order` is specified, the set of distinct on properties must appear before the non-distinct on properties in `order`.
      - `name` string — A reference to a property. Requires: * MUST be a dot-delimited (`.`) string of segments, where each segment conforms to entity property name limitations.
    - `offset` integer — The number of results to skip. Applies before limit, but after all other constraints. Optional. Must be >= 0 if specified.
    - `findNearest` FindNearest — Nearest Neighbors search config. The ordering provided by FindNearest supersedes the order_by stage. If multiple documents have the same vector distance, the returned document order is not guaranteed to be stable between queries.
      - `vectorProperty` PropertyReference — A reference to a property relative to the kind expressions.
        - `name` string — A reference to a property. Requires: * MUST be a dot-delimited (`.`) string of segments, where each segment conforms to entity property name limitations.
      - `distanceThreshold` number, double — Optional. Option to specify a threshold for which no less similar documents will be returned. The behavior of the specified `distance_measure` will affect the meaning of the distance threshold. Since DOT_PRODUCT distances increase when the vectors are more similar, the comparison is inverted. * For EUCLIDEAN, COSINE: WHERE distance <= distance_threshold * For DOT_PRODUCT: WHERE distance >= distance_threshold
      - `distanceMeasure` 'DISTANCE_MEASURE_UNSPECIFIED' | 'EUCLIDEAN' | 'COSINE' | 'DOT_PRODUCT' — Required. The Distance Measure to use, required.
      - `limit` integer — Required. The number of nearest neighbors to return. Must be a positive integer of no more than 100.
      - `queryVector` Value — A message that can hold any of the supported value types and associated metadata.
        - `booleanValue` boolean — A boolean value.
        - `arrayValue` ArrayValue — An array value.
          - `values` Value[] — Values in the array. The order of values in an array is preserved as long as all values have identical settings for 'exclude_from_indexes'.
        - `meaning` integer — The `meaning` field should only be populated for backwards compatibility.
        - `keyValue` Key — A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.
          - `partitionId` PartitionId — A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `""`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\d\.\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.
            - `projectId` string — The ID of the project to which the entities belong.
            - `databaseId` string — If not empty, the ID of the database to which the entities belong.
            - `namespaceId` string — If not empty, the ID of the namespace to which the entities belong.
          - `path` PathElement[] — The entity path. An entity path consists of one or more elements composed of a kind and a string or numerical identifier, which identify entities. The first element identifies a _root entity_, the second element identifies a _child_ of the root entity, the third element identifies a child of the second entity, and so forth. The entities identified by all prefixes of the path are called the element's _ancestors_. An entity path is always fully complete: *all* of the entity's ancestors are required to be in the path along with the entity identifier itself. The only exception is that in some documented cases, the identifier in the last path element (for the entity) itself may be omitted. For example, the last path element of the key of `Mutation.insert` may have no identifier. A path can never be empty, and a path can have at most 100 elements.
            - `name` string — The name of the entity. A name matching regex `__.*__` is reserved/read-only. A name must not be more than 1500 bytes when UTF-8 encoded. Cannot be `""`. Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are encoded as `__bytes__` where `` is the base-64 encoding of the bytes.
            - `kind` string — The kind of the entity. A kind matching regex `__.*__` is reserved/read-only. A kind must not contain more than 1500 bytes when UTF-8 encoded. Cannot be `""`. Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are encoded as `__bytes__` where `` is the base-64 encoding of the bytes.
            - `id` string, int64 — The auto-allocated ID of the entity. Never equal to zero. Values less than zero are discouraged and may not be supported in the future.
        - `nullValue` 'NULL_VALUE' — A null value.
        - `geoPointValue` LatLng — An object that represents a latitude/longitude pair. This is expressed as a pair of doubles to represent degrees latitude and degrees longitude. Unless specified otherwise, this object must conform to the WGS84 standard. Values must be within normalized ranges.
          - `longitude` number, double — The longitude in degrees. It must be in the range [-180.0, +180.0].
          - `latitude` number, double — The latitude in degrees. It must be in the range [-90.0, +90.0].
        - `doubleValue` number, double — A double value.
        - `entityValue` Entity — A Datastore data object. Must not exceed 1 MiB - 4 bytes.
          - `properties` object — The entity's properties. The map's keys are property names. A property name matching regex `__.*__` is reserved. A reserved property name is forbidden in certain documented contexts. The map keys, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty.
          - `key` Key — A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.
            - `partitionId` PartitionId — A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `""`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\d\.\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.
              - …
            - `path` PathElement[] — The entity path. An entity path consists of one or more elements composed of a kind and a string or numerical identifier, which identify entities. The first element identifies a _root entity_, the second element identifies a _child_ of the root entity, the third element identifies a child of the second entity, and so forth. The entities identified by all prefixes of the path are called the element's _ancestors_. An entity path is always fully complete: *all* of the entity's ancestors are required to be in the path along with the entity identifier itself. The only exception is that in some documented cases, the identifier in the last path element (for the entity) itself may be omitted. For example, the last path element of the key of `Mutation.insert` may have no identifier. A path can never be empty, and a path can have at most 100 elements.
              - …
        - `stringValue` string — A UTF-8 encoded string value. When `exclude_from_indexes` is false (it is indexed) , may have at most 1500 bytes. Otherwise, may be set to at most 1,000,000 bytes.
        - `blobValue` string, byte — A blob value. May have at most 1,000,000 bytes. When `exclude_from_indexes` is false, may have at most 1500 bytes. In JSON requests, must be base64-encoded.
        - `timestampValue` string, google-datetime — A timestamp value. When stored in the Datastore, precise only to microseconds; any additional precision is rounded down.
        - `excludeFromIndexes` boolean — If the value should be excluded from all indexes including those defined explicitly.
        - `integerValue` string, int64 — An integer value.
      - `distanceResultProperty` string — Optional. Optional name of the field to output the result of the vector distance calculation. Must conform to entity property limitations.
    - `filter` Filter — A holder for any type of filter.
      - `compositeFilter` CompositeFilter — A filter that merges multiple other filters using the given operator.
        - `filters` Filter[] — The list of filters to combine. Requires: * At least one filter is present.
        - `op` 'OPERATOR_UNSPECIFIED' | 'AND' | 'OR' — The operator for combining multiple filters.
      - `propertyFilter` PropertyFilter — A filter on a specific property.
        - `op` 'OPERATOR_UNSPECIFIED' | 'LESS_THAN' | 'LESS_THAN_OR_EQUAL' | 'GREATER_THAN' | 'GREATER_THAN_OR_EQUAL' | 'EQUAL' | 'IN' | 'NOT_EQUAL' | 'HAS_ANCESTOR' | 'NOT_IN' — The operator to filter by.
        - `value` Value — A message that can hold any of the supported value types and associated metadata.
          - `booleanValue` boolean — A boolean value.
          - `arrayValue` ArrayValue — An array value.
            - `values` Value[] — Values in the array. The order of values in an array is preserved as long as all values have identical settings for 'exclude_from_indexes'.
          - `meaning` integer — The `meaning` field should only be populated for backwards compatibility.
          - `keyValue` Key — A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.
            - `partitionId` PartitionId — A partition ID identifies a grouping of entities. The grouping is always by project and namespace, however the namespace ID may be empty. A partition ID contains several dimensions: project ID and namespace ID. Partition dimensions: - May be `""`. - Must be valid UTF-8 bytes. - Must have values that match regex `[A-Za-z\d\.\-_]{1,100}` If the value of any dimension matches regex `__.*__`, the partition is reserved/read-only. A reserved/read-only partition ID is forbidden in certain documented contexts. Foreign partition IDs (in which the project ID does not match the context project ID ) are discouraged. Reads and writes of foreign partition IDs may fail if the project is not in an active state.
              - …
            - `path` PathElement[] — The entity path. An entity path consists of one or more elements composed of a kind and a string or numerical identifier, which identify entities. The first element identifies a _root entity_, the second element identifies a _child_ of the root entity, the third element identifies a child of the second entity, and so forth. The entities identified by all prefixes of the path are called the element's _ancestors_. An entity path is always fully complete: *all* of the entity's ancestors are required to be in the path along with the entity identifier itself. The only exception is that in some documented cases, the identifier in the last path element (for the entity) itself may be omitted. For example, the last path element of the key of `Mutation.insert` may have no identifier. A path can never be empty, and a path can have at most 100 elements.
              - …
          - `nullValue` 'NULL_VALUE' — A null value.
          - `geoPointValue` LatLng — An object that represents a latitude/longitude pair. This is expressed as a pair of doubles to represent degrees latitude and degrees longitude. Unless specified otherwise, this object must conform to the WGS84 standard. Values must be within normalized ranges.
            - `longitude` number, double — The longitude in degrees. It must be in the range [-180.0, +180.0].
            - `latitude` number, double — The latitude in degrees. It must be in the range [-90.0, +90.0].
          - `doubleValue` number, double — A double value.
          - `entityValue` Entity — A Datastore data object. Must not exceed 1 MiB - 4 bytes.
            - `properties` object — The entity's properties. The map's keys are property names. A property name matching regex `__.*__` is reserved. A reserved property name is forbidden in certain documented contexts. The map keys, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty.
            - `key` Key — A unique identifier for an entity. If a key's partition ID or any of its path kinds or names are reserved/read-only, the key is reserved/read-only. A reserved/read-only key is forbidden in certain documented contexts.
              - …
          - `stringValue` string — A UTF-8 encoded string value. When `exclude_from_indexes` is false (it is indexed) , may have at most 1500 bytes. Otherwise, may be set to at most 1,000,000 bytes.
          - `blobValue` string, byte — A blob value. May have at most 1,000,000 bytes. When `exclude_from_indexes` is false, may have at most 1500 bytes. In JSON requests, must be base64-encoded.
          - `timestampValue` string, google-datetime — A timestamp value. When stored in the Datastore, precise only to microseconds; any additional precision is rounded down.
          - `excludeFromIndexes` boolean — If the value should be excluded from all indexes including those defined explicitly.
          - `integerValue` string, int64 — An integer value.
        - `property` PropertyReference — A reference to a property relative to the kind expressions.
          - `name` string — A reference to a property. Requires: * MUST be a dot-delimited (`.`) string of segments, where each segment conforms to entity property name limitations.
    - `order` PropertyOrder[] — The order to apply to the query results (if empty, order is unspecified).
      - `direction` 'DIRECTION_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING' — The direction to order by. Defaults to `ASCENDING`.
      - `property` PropertyReference — A reference to a property relative to the kind expressions.
        - `name` string — A reference to a property. Requires: * MUST be a dot-delimited (`.`) string of segments, where each segment conforms to entity property name limitations.
    - `kind` KindExpression[] — The kinds to query (if empty, returns entities of all kinds). Currently at most 1 kind may be specified.
      - `name` string — The name of the kind.
    - `projection` Projection[] — The projection to return. Defaults to returning all properties.
      - `property` PropertyReference — A reference to a property relative to the kind expressions.
        - `name` string — A reference to a property. Requires: * MUST be a dot-delimited (`.`) string of segments, where each segment conforms to entity property name limitations.
    - `limit` integer — The maximum number of results to return. Applies after all other constraints. Optional. Unspecified is interpreted as no limit. Must be >= 0 if specified.

## Response `200`

Successful response

---

[API](https://skmtc.dev/google/apis/datastore.md) · [All operations](https://skmtc.dev/google/apis/datastore/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/google/datastore/revisions/aef4907227b2/schema)
