Area: API Issues
Sub-Area: GraphQL Query Performance & Pagination
Applies to: OSS + Cloud
Issue
You need many results from the DataHub GraphQL API, for example every dataset on a platform. You ask for a very large count in one call, or you page with start and count deep into the result set. Requests get slow, time out, or stop returning results after 10,000 entities. Large queries can also slow down the UI and other API users of the same instance.
You Might Be Asking
- How do I page through more than 10,000 search results in the GraphQL API?
- What is the largest
countI can set on one search request? - Why do I get fewer results than the
countI asked for? - How do I export all datasets for a platform without overloading DataHub?
- How do I query lineage without one huge nested query?
Cause
DataHub's GraphQL API is built to power the UI. It works best with small pages, few fields per result, and shallow queries.
The search* queries (search, searchAcrossEntities, searchAcrossLineage) use start and count paging. They are built for shallow paging, about 50 pages or fewer. They cannot page past 10,000 results.
The server also caps the result count of one search request at 10,000. With the default settings, a request with count above 10,000 does not fail. The server replaces the count with 5,000, logs a warning, and returns at most 5,000 results.
Every field you select is resolved for every result. A large page combined with many nested fields multiplies the work on the server.
Solution
-
Use
scrollAcrossEntitiesto read large or complete result sets. Sort onurnso the order stays stable between pages. Send thenextScrollIdfrom each response asscrollIdin the next request. Stop whennextScrollIdis null. See GraphQL Best Practices and Searching at Scale.query scrollDatasets { scrollAcrossEntities( input: { types: [DATASET] query: "*" count: 100 scrollId: null sortInput: { sortCriteria: [{ field: "urn", sortOrder: ASCENDING }] } } ) { nextScrollId total searchResults { entity { urn } } } }For the next page, run the same query with
scrollIdset to thenextScrollIdvalue from the previous response. -
Use
searchorsearchAcrossEntitieswithstartandcountonly for shallow paging, such as a results page in your own tool. Increasestartbycountfor each page. Keep the total under 10,000 results.query searchDatasetsPage { search(input: { type: DATASET, query: "*", start: 0, count: 100 }) { start count total searchResults { entity { urn } } } } -
Keep
countsmall. Do not set it above 10,000: the server does not return more than that, and with default settings it returns 5,000 instead. On a self-hosted (OSS) deployment, you can setSEARCH_SERVICE_LIMIT_RESULTS_STRICT=trueon GMS to reject such a request with the errorResult count exceeds limit of 10000instead. -
Filter on the server so you read fewer results. Use
orFilters; the olderfiltersinput is deprecated. Theplatformfield holds a platform URN, so useurn:li:dataPlatform:snowflake, notsnowflake. Theoriginfield holds the environment, such asPROD.query searchFilteredDatasets { scrollAcrossEntities( input: { types: [DATASET] query: "*" count: 100 orFilters: [ { and: [ { field: "platform", values: ["urn:li:dataPlatform:snowflake"] } { field: "origin", values: ["PROD"] } ] } ] sortInput: { sortCriteria: [{ field: "urn", sortOrder: ASCENDING }] } } ) { nextScrollId searchResults { entity { urn } } } } -
Request only the fields you need. When you list many entities, select only
urn(and maybe a name) in the scroll query. Then fetch details such as ownership, tags or glossary terms for the entities you care about in separate, smaller requests.query lightQuery { dataset(urn: "urn:li:dataset:(urn:li:dataPlatform:snowflake,db.schema.my_table,PROD)") { urn properties { name description } platform { name } } } -
Query lineage one hop at a time, with paging. The
Datasettype has noupstreamLineagefield; use thelineagefield with a direction,startandcount. For several hops, usesearchAcrossLineageorscrollAcrossLineageinstead of nesting queries inside each other.query upstreamOneHop { dataset(urn: "urn:li:dataset:(urn:li:dataPlatform:snowflake,db.schema.my_table,PROD)") { lineage(input: { direction: UPSTREAM, start: 0, count: 100 }) { total relationships { degree entity { urn } } } } } -
To export URNs from Python, use the SDK.
DataHubGraph.get_urns_by_filterusesscrollAcrossEntitiesand handles the scroll IDs for you. Itsplatformargument takes a platform name and converts it to a URN.from datahub.ingestion.graph.client import DataHubGraph from datahub.ingestion.graph.config import DatahubClientConfig graph = DataHubGraph(DatahubClientConfig(server="https://<your-datahub>/gms", token="<token>")) for urn in graph.get_urns_by_filter(entity_types=["dataset"], platform="snowflake", env="PROD"): print(urn)
If you use DataHub Cloud and the instance stays slow after you reduce your query sizes, contact DataHub Support with the queries your scripts run.
Related Documentation
Tags: graphql, api, performance, pagination, scroll, scrollAcrossEntities, bulk-export, best-practices