The result of a Google Cloud Datastore query submission. When the result is not typed it is
possible to cast it to its appropriate type according to the #getResultClass value.
Results are loaded lazily in batches, where batch size is set by Cloud Datastore. As a result, it
is possible to get a DatastoreException upon hasNext or next calls.
Returns the Cursor for the point after the value returned in the last #next call. This
cursor can be used to issue subsequent queries (with the same constraints) that may return
additional results.
A simple use case:
Query<Entity>query=Query.newEntityQueryBuilder().setKind("Person").setFilter(PropertyFilter.eq("favoriteFood","pizza")).build();QueryResults<Entity>results=datastore.run(query);// Consume some results (using results.next()) and do any other actions as necessary.query=query.toBuilder().setStartCursor(results.getCursorAfter()).build();results=datastore.run(query);// now we will iterate over all entities not yet consumed
[[["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-09-04 UTC."],[],[],null,["# Interface QueryResults<V> (2.31.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.31.2 (latest)](/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.QueryResults)\n- [2.31.1](/java/docs/reference/google-cloud-datastore/2.31.1/com.google.cloud.datastore.QueryResults)\n- [2.30.0](/java/docs/reference/google-cloud-datastore/2.30.0/com.google.cloud.datastore.QueryResults)\n- [2.29.1](/java/docs/reference/google-cloud-datastore/2.29.1/com.google.cloud.datastore.QueryResults)\n- [2.28.2](/java/docs/reference/google-cloud-datastore/2.28.2/com.google.cloud.datastore.QueryResults)\n- [2.27.1](/java/docs/reference/google-cloud-datastore/2.27.1/com.google.cloud.datastore.QueryResults)\n- [2.26.4](/java/docs/reference/google-cloud-datastore/2.26.4/com.google.cloud.datastore.QueryResults)\n- [2.25.2](/java/docs/reference/google-cloud-datastore/2.25.2/com.google.cloud.datastore.QueryResults)\n- [2.24.3](/java/docs/reference/google-cloud-datastore/2.24.3/com.google.cloud.datastore.QueryResults)\n- [2.23.0](/java/docs/reference/google-cloud-datastore/2.23.0/com.google.cloud.datastore.QueryResults)\n- [2.22.0](/java/docs/reference/google-cloud-datastore/2.22.0/com.google.cloud.datastore.QueryResults)\n- [2.21.3](/java/docs/reference/google-cloud-datastore/2.21.3/com.google.cloud.datastore.QueryResults)\n- [2.20.2](/java/docs/reference/google-cloud-datastore/2.20.2/com.google.cloud.datastore.QueryResults)\n- [2.19.2](/java/docs/reference/google-cloud-datastore/2.19.2/com.google.cloud.datastore.QueryResults)\n- [2.18.5](/java/docs/reference/google-cloud-datastore/2.18.5/com.google.cloud.datastore.QueryResults)\n- [2.17.6](/java/docs/reference/google-cloud-datastore/2.17.6/com.google.cloud.datastore.QueryResults) \n\n public interface QueryResults\u003cV\u003e extends Iterator\u003cV\u003e\n\nThe result of a Google Cloud Datastore query submission. When the result is not typed it is\npossible to cast it to its appropriate type according to the #getResultClass value.\nResults are loaded lazily in batches, where batch size is set by Cloud Datastore. As a result, it\nis possible to get a `DatastoreException` upon hasNext or next calls. \n\nImplements\n----------\n\n[Iterator\\\u003cV\\\u003e](https://docs.oracle.com/javase/8/docs/api/java/util/Iterator\u003cV\u003e.html)\n\nMethods\n-------\n\n### getCursorAfter()\n\n public abstract Cursor getCursorAfter()\n\nReturns the Cursor for the point after the value returned in the last #next call. This\ncursor can be used to issue subsequent queries (with the same constraints) that may return\nadditional results.\n\nA simple use case: \n\n\n Query\u003cEntity\u003e query = Query.newEntityQueryBuilder()\n .setKind(\"Person\")\n .setFilter(PropertyFilter.eq(\"favoriteFood\", \"pizza\"))\n .build();\n QueryResults\u003cEntity\u003e results = datastore.run(query);\n // Consume some results (using results.next()) and do any other actions as necessary.\n query = query.toBuilder().setStartCursor(results.getCursorAfter()).build();\n results = datastore.run(query); // now we will iterate over all entities not yet consumed\n \n### getExplainMetrics()\n\n public abstract Optional\u003cExplainMetrics\u003e getExplainMetrics()\n\n| **Beta**\n|\n| This feature is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.\n\n### getMoreResults()\n\n public abstract QueryResultBatch.MoreResultsType getMoreResults()\n\nReturns MoreResults state of the query after the current batch.\n\n### getResultClass()\n\n public abstract Class\u003c?\u003e getResultClass()\n\nReturns the actual class of the result's values.\n\n### getSkippedResults()\n\n public abstract int getSkippedResults()\n\nReturns the number of results skipped, typically because of an offset.\n\nA simple use case to count entities: \n\n\n Query\u003cKey\u003e query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();\n QueryResults\u003cKey\u003e result = datasore.datastore.run(query);\n if (!result.hasNext()) {\n int numberOfEntities = result.getSkippedResults();\n }"]]