“Invalid prefix filter with property reference emyspace, myview/94b12855a09cf4, externalId]. View myspace:myview/94b12855a09cf4 does not have property externalId.”
Could you help find out how to apply a startWith filter on externalId in python sdk?
Regards,
Xiaofeng
Page 1 / 1
@Xiaofeng Wang, ViewId type does not have a property externalId, but does have a property ‘external_id’
Are you trying to filter views based on external_id? If so, I’m a bit confused, because retrieving views by id explicitly will only retrieve one.
What type is the ‘filters’ object you have above?
-Jason
Hi Jason,
filters is a build in object in Cognite pythonSDK:
import cognite.client.data_classes.filters as filters
I am trying to filter instances, so the next step I did is:
The code above works well, but I don’t know how to do filtering on externalId, instead of “workflow” property.
The external_id for a viewId is the name of the view, which doesn’t help in our case:
Our externalId of the instances looks like “XXXX:{instanceName}”, and I would like to find out all the instances with the “XXXX” as prefix in their externalId.
-Xiaofeng
@Xiaofeng Wang, Ok, so you’re filtering instances, not views.
Please find a working sample. The filter is a dictionary which is the same as the JSON payload which you can find in the API docs.
from cognite.client import CogniteClient from cognite.client.data_classes.data_modeling.spaces import Space, SpaceList from cognite.client.data_classes.data_modeling import ViewList, View from cognite.client.data_classes.data_modeling import ContainerList, Container from cognite.client.data_classes.data_modeling import DataModelList, DataModel from cognite.client.data_classes.data_modeling import NodeList, Node, EdgeList, Edge
client: CogniteClient = .... # Get your client your way
# The filter is a dictionary emily_actors = { "and": d { "equals": { "property": y "node", "space" ], "value": "imdb" } }, { "prefix": { "property": y "node", "externalId" ], "value": "a-emily" } } ] }
Also it would be very helpful if you can let me know where I can find the how to compose the filters. Below is the example from the API document. and I could not make any meaning filter based on that sample. Is there any other documents with more detailed examples?
@Xiaofeng Wang, Which project and which model are you wanting to query? I can work to build examples from that.
-Jason
@Jason Dressel You can use xwsdm in slb_simuations for testing. We would like to query the property instances with Prefix filter on externalID(for example, ‘df023726-a8e9-43a2-8dfc-00578daf93a4’) and Equal filter on workflow(for example, ‘measured’)
Regards,
Xiaofeng
@Xiaofeng Wang In the end, it was a bit easier to provide an imdb base example
This ‘and’ filter get’s all nodes with externalId prefixed with ‘a-emily’ AND in the space imdb.
This syntax is not easy to find out through the API document as mentioned in the call. Hopefully it will be improved and add a bit more examples if the syntax is not very straightforward.
Furthermore, it would be good to get it work with PythonSDK which is more elegant. And the pythonSDK document should have more examples regarding how to do filtering.
Will flag this as resolved for now. Thanks for your help!