Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Cursor

How to get large amounts of documents using batch retrieval. The backend system preserves the state of the result set.

The cursor argument enables stateful batch retrieval in Optimizely Graph so that you can pull large result sets one page at a time without losing track of the position in the index. Use it when a single query would otherwise hit the result-size limit, when you need to iterate the full result set for a delta import, or when consistent paging across many batches matters more than ad hoc offsets.

By default, the cursor is not enabled. To enable it, select cursor in the GraphQL query in combination with a query in where using an empty string "" as value, such as cursor: "".

  • The response has a cursor value and then gets the next batches using that cursor value in the GraphQL query.
  • Optimizely Graph preserves the results for the first query in the current state (stateful) for 10 minutes per request. After that time, the cursor expires and is no longer valid.
  • Continue until there are no more results. The number of results per batch depends on the number set by limit. For the first query with the cursor enabled, skip is ignored. Implement this by ignoring the first batches of results.
  • Sort by DOC for the fastest retrieval.
  • Project at least one content item field, or an error displays. The total field alone is insufficient because it is not a field of an item in items.

The following example request retrieves the batches one document at a time:

{
  StandardPage(
    cursor: "FGluY2x1ZGVfY29udGV4dF91dWlkDXF1ZXJ5QW5kRmV0Y2gBFnh3Qmszbmh0UkxPeWVGVHBLcUtQVWcAAAAAAAAATRZJVkJ4eFZBdVM5dTI4R1UzVUFSOEpn"
    limit: 1
    orderBy: {_ranking: DOC}
  ) {
    items {
      Name
      Url
      RouteSegment
      Changed
    }
    cursor
  }
}