Skip to main content
Question

Incomplete Solution slide?


Forum|alt.badge.img

The first hands-on exercises in module Data Engineer Basics Integrations, Learn to use the Cognite Python SDK, is hard to understand. The task is,

  1. Use the AssetAPI.search function to find the “Europe” asset (there will be multiple assets with this name in the cdf project, we are looking for the one with id=349354003007241)

The Solution slide simply says to do, `client.assets.search(”Europe”)`. But this gives multiple (two) assets, and the task is specifically to get the one with id=349354003007241. How can I query or filter the CDF to give me specifically this asset? Or is the point here to not do this in the query, but rather get all (both) Europe assets and then filter “offline”, in Python? I think the Solution slide is incomplete.

Forum|alt.badge.img

The documentation says,

Search for assets Primarily meant for human-centric use-cases and data exploration, not for programs, since matching and ordering may change over time. Use the list function if stable or exact matches are required.

Parameters

  • name (str | None) – Fuzzy match on name.

  • description (str | None) – Fuzzy match on description.

  • query (str | None) – Whitespace-separated terms to search for in assets. Does a best-effort fuzzy search in relevant fields (currently name and description) for variations of any of the search terms, and orders results by relevance.

  • filter (AssetFilter | dict[strAnyNone) – Filter to apply. Performs exact match on these fields.

  • limit (int) – Maximum number of results to return.

Returns

List of requested assets

Return type

AssetList

 

However, it doesn’t seem to be possible to use any field in the filter method? I am able to filter on name, but (for some reason) not on id or parent_id etc:
 

client.assets.search(filter={"name": "Europe"})  # works

client.assets.search(filter={"id": "349354003007241"})  # fails
CogniteAPIError: Unexpected field - filter.id | code: 400

 

There seems to be some set of searchable fields which can be used in filter, but some of these must be used in plural form. You can filter on name, but you can’t filter on {“parent_id”: “VALUE”}, you have to do {“parent_ids”: [VALUE]}. It seems id (or “ids”) is not a supported field? Is there a list of supported fields? Could the solution address this issue?


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img

@Joakim Grahl Knudsen I’ll check on this with the Academy team and get back to you with an update.


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings