Stay organized with collections Save and categorize content based on your preferences.
This API is supported for first-generation runtimes and can be used when upgrading to corresponding second-generation runtimes. If you are updating to the App Engine Java 11/17 runtime, refer to the migration guide to learn about your migration options for legacy bundled services.After constructing a query, you can specify a number of retrieval options to further control the results it returns. See datastore queries for more information on structuring queries for your app.
Retrieving a single entityTo retrieve just a single entity matching your query, use the method PreparedQuery.asSingleEntity()
:
This returns the first result found in the index that matches the query. (If there is more than one matching result, it throws a TooManyResultsException
.)
When iterating through the results of a query using the PreparedQuery.asIterable()
and PreparedQuery.asIterator()
methods, Cloud Datastore retrieves the results in batches. By default each batch contains 20 results, but you can change this value using FetchOptions.chunkSize()
. You can continue iterating through query results until all are returned or the request times out.
To retrieve only selected properties of an entity rather than the entire entity, use a projection query. This type of query runs faster and costs less than one that returns complete entities.
Similarly, a keys-only query saves time and resources by returning just the keys to the entities it matches, rather than the full entities themselves. To create this type of query, use the Query.setKeysOnly()
method:
You can specify a limit for your query to control the maximum number of results returned in one batch. The following example retrieves the five tallest people from Cloud Datastore:
What's next?Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This API supports first-generation runtimes and is applicable when upgrading to corresponding second-generation runtimes, while migration to Java 11/17 runtimes requires referring to a specific migration guide."],["`PreparedQuery.asSingleEntity()` retrieves a single entity matching a query, throwing a `TooManyResultsException` if multiple matches exist."],["`PreparedQuery.asIterable()` and `PreparedQuery.asIterator()` allow iterating through query results in batches, with the batch size adjustable via `FetchOptions.chunkSize()`."],["Projection queries retrieve only selected properties, and keys-only queries retrieve only keys, both being faster and less resource-intensive than full-entity queries."],["A limit can be set on queries to control the maximum number of results, as demonstrated in the example that retrieves the five tallest people."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4