Stay organized with collections Save and categorize content based on your preferences.
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 Query.get()
(or GqlQuery.get()
):
q = Person.all()
q.filter("last_name =", target_last_name)
result = q.get()
This returns the first result found in the index that matches the query.
Iterating through query resultsWhen iterating through the results of a query using the run()
method of a Query
or GqlQuery
object, Cloud Datastore retrieves the results in batches. By default each batch contains 20 results, but you can change this value using the method's batch_size
parameter. 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, set keys_only=True
when constructing the query object:
q = Person.all(keys_only=True)
Setting a limit for your query
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:
q = Person.all()
q.order("-height")
for p in q.run(limit=5):
print "%s %s, %d inches tall" % (p.first_name, p.last_name, p.height)
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."],[[["You can refine query results by using various retrieval options to control the data returned."],["The `Query.get()` method allows for the retrieval of a single entity that matches the query criteria."],["Query results can be iterated through in batches, with the default batch size being 20, which can be adjusted with the `batch_size` parameter."],["Projection queries allow you to retrieve only selected properties of an entity, enhancing query speed and efficiency, while keys-only queries only return the keys to the entities, saving time and resources."],["A limit can be set on queries to restrict the number of results returned in a single batch, useful for controlling the amount of data processed."]]],[]]
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