Stay organized with collections
Save and categorize content based on your preferences.
publicfinalclassFetchOptions
Describes the limit, offset, and chunk size to be applied when executing a PreparedQuery.
limit is the maximum number of results the query will return.
offset is the number of results to skip before returning any results. Results that are
skipped due to offset do not count against limit. Note: Using offset still retrieves skipped entities internally. This affects the
latency of the query, and your application is billed for the operations required to
retrieve them. Using cursors lets you avoid these costs.
startCursor and endCursor are previously generated cursors that point to
locations in a result set. If specified queries will start and end at these locations.
prefetchSize is the number of results retrieved on the first call to the datastore.
Note that unlike limit, offset and cursor, prefetchSize and
chunkSize have no impact on the result of the PreparedQuery, but rather only the
performance of the PreparedQuery.
Notes on usage:
The recommended way to instantiate a FetchOptions object is to import FetchOptions and invoke a static creation method followed by an instance mutator (if needed):
[[["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."],[[["\u003cp\u003e\u003ccode\u003eFetchOptions\u003c/code\u003e defines the limit, offset, and chunk size for executing a \u003ccode\u003ePreparedQuery\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003elimit\u003c/code\u003e specifies the maximum number of results returned, while \u003ccode\u003eoffset\u003c/code\u003e determines how many results to skip, and skipped results are still retrieved internally, affecting latency and billing.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estartCursor\u003c/code\u003e and \u003ccode\u003eendCursor\u003c/code\u003e define the start and end points in a result set, enabling queries to begin and end at specific locations.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eprefetchSize\u003c/code\u003e dictates the number of results fetched in the initial datastore call, and \u003ccode\u003echunkSize\u003c/code\u003e controls the chunking strategy of the \u003ccode\u003eIterator\u003c/code\u003e and \u003ccode\u003eIterable\u003c/code\u003e, both of which influence performance but not the query's outcome.\u003c/p\u003e\n"],["\u003cp\u003eTo use \u003ccode\u003eFetchOptions\u003c/code\u003e, one should import \u003ccode\u003ecom.google.appengine.api.datastore.FetchOptions\u003c/code\u003e and use static creation methods, for example, \u003ccode\u003eFetchOptions.Builder.withLimit(10)\u003c/code\u003e to set the max number of results.\u003c/p\u003e\n"]]],[],null,["# Class FetchOptions (2.0.0)\n\n public final class FetchOptions\n\nDescribes the limit, offset, and chunk size to be applied when executing a [PreparedQuery](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery).\n\n`limit` is the maximum number of results the query will return.\n\n`offset` is the number of results to skip before returning any results. Results that are\nskipped due to offset do not count against `limit`. \n\n**Note:** Using `offset` still retrieves skipped entities internally. This affects the\nlatency of the query, and **your application is billed for the operations** required to\nretrieve them. Using cursors lets you avoid these costs.\n\n`startCursor` and `endCursor` are previously generated cursors that point to\nlocations in a result set. If specified queries will start and end at these locations.\n\n`prefetchSize` is the number of results retrieved on the first call to the datastore.\n\n`chunkSize` determines the internal chunking strategy of the [Iterator](https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html) returned\nby [PreparedQuery#asIterator(FetchOptions)](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery#com_google_appengine_api_datastore_PreparedQuery_asIterator_com_google_appengine_api_datastore_FetchOptions_) and the [Iterable](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html) returned by [PreparedQuery#asIterable(FetchOptions)](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery#com_google_appengine_api_datastore_PreparedQuery_asIterable_com_google_appengine_api_datastore_FetchOptions_).\n\nNote that unlike `limit`, `offset` and `cursor`, `prefetchSize` and\n`chunkSize` have no impact on the result of the [PreparedQuery](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery), but rather only the\nperformance of the [PreparedQuery](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery).\n\nNotes on usage: \n\nThe recommended way to instantiate a `FetchOptions` object is to import [FetchOptions](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions) and invoke a static creation method followed by an instance mutator (if needed): \n\n\n import com.google.appengine.api.datastore.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions.html;\n\n https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Cursor.html cursor = ...\n\n ...\n\n // limit 10\n datastoreService.prepare(query).https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery.html#com_google_appengine_api_datastore_PreparedQuery_asList_com_google_appengine_api_datastore_FetchOptions_(https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions.html.Builder.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions.Builder.html#com_google_appengine_api_datastore_FetchOptions_Builder_withLimit_int_(10));\n\n // limit 10, start cursor\n datastoreService.prepare(query).https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreparedQuery.html#com_google_appengine_api_datastore_PreparedQuery_asList_com_google_appengine_api_datastore_FetchOptions_(https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions.html.Builder.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions.Builder.html#com_google_appengine_api_datastore_FetchOptions_Builder_withLimit_int_(10).https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions.html#com_google_appengine_api_datastore_FetchOptions_startCursor_com_google_appengine_api_datastore_Cursor_(cursor));\n \nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e FetchOptions \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Fields\n-------------\n\n### DEFAULT_CHUNK_SIZE (deprecated)\n\n public static final int DEFAULT_CHUNK_SIZE\n\n**Deprecated.** *Instead of using DEFAULT_CHUNK_SIZE, do not specify a chunk size.*\n\nMethods\n-------\n\n### chunkSize(int chunkSize)\n\n public FetchOptions chunkSize(int chunkSize)\n\nSets the chunk size. Please read the class javadoc for an explanation of how chunk size is\nused.\n\n### cursor(Cursor cursor) (deprecated)\n\n public FetchOptions cursor(Cursor cursor)\n\n**Deprecated.** *use [#startCursor](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions#com_google_appengine_api_datastore_FetchOptions_startCursor_) instead.*\n\nSets the cursor to start the query from.\n\n### endCursor(Cursor endCursor)\n\n public FetchOptions endCursor(Cursor endCursor)\n\nSets the cursor at which to end the query.\n\n### equals(@Nullable Object obj)\n\n public boolean equals(@Nullable Object obj)\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### getChunkSize()\n\n public @Nullable Integer getChunkSize()\n\nReturns the chunk size, or `null` if no chunk size was provided.\n\n### getCursor() (deprecated)\n\n public @Nullable Cursor getCursor()\n\n**Deprecated.** *use [#getStartCursor()](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.FetchOptions#com_google_appengine_api_datastore_FetchOptions_getStartCursor__) instead*\n\n### getEndCursor()\n\n public @Nullable Cursor getEndCursor()\n\nReturns the end cursor, or `null` if no end cursor was provided.\n\n### getLimit()\n\n public @Nullable Integer getLimit()\n\nReturns the limit, or `null` if no limit was provided.\n\n### getOffset()\n\n public @Nullable Integer getOffset()\n\nReturns the offset, or `null` if no offset was provided.\n\n### getPrefetchSize()\n\n public @Nullable Integer getPrefetchSize()\n\nReturns the prefetch size, or `null` if no prefetch size was provided.\n\n### getStartCursor()\n\n public @Nullable Cursor getStartCursor()\n\nReturns the start cursor, or `null` if no start cursor was provided.\n\n### hashCode()\n\n public int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### limit(int limit)\n\n public FetchOptions limit(int limit)\n\nSets the limit. Please read the class javadoc for an explanation of how limit is used.\n\n### offset(int offset)\n\n public FetchOptions offset(int offset)\n\nSets the offset. Please read the class javadoc for an explanation of how offset is used.\n\n### prefetchSize(int prefetchSize)\n\n public FetchOptions prefetchSize(int prefetchSize)\n\nSets the number of entities to prefetch.\n\n### startCursor(Cursor startCursor)\n\n public FetchOptions startCursor(Cursor startCursor)\n\nSets the cursor at which to start the query.\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)"]]