Greeting fellow travellers:
I am querying my portal for feature service types. By default it returns the hosted feature layer and the views on the hosted feature layer. I would like to do something with the hosted feature layers and ignore the hosted feature layer views. Code looks like this:
the_query = "type:Feature Service"
some_content = gis.content.search(query=the_query, max_items=10000, outside_org=False)
for a_layer in some_content:
# do something if it's a hosted feature layer, ignore it if it's a view
How do I get just the layers and ignore the views?
Thanks in advance, please and thank you.
Solved! Go to Solution.
There are two ways you can do this. Both rely on typeKeywords. When you create a View, I believe a type keyword is automatically attached to it (this is true in the UI, at least).
You can do something like this with your query string to filter out views:
the_query = "NOT typekeywords:View Service AND owner:youruser"
Or, in your loop you can use Item.typeKeywords to isolate views if you need to do further manipulations. The typeKeywords property for a view should be equal to a list like so:
['ArcGIS Server', 'Data', 'Feature Access', 'Feature Service', 'Service', 'Singlelayer', 'Hosted Service', 'View Service']
So, you can do: if "View Service" in item.typeKeywords do this or that.
Hi,
I don't see an elegant way to do this in the search.
I have not tested this but it looks like for each feature layer in your search results, you could retrieve the related items (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.related_items) in the forward direction, using the Service2Data relationship type (you might need to play around with the parameters). If there aren't any related items, then it isn't a view.
Does that get you what you need?
Jill
There are two ways you can do this. Both rely on typeKeywords. When you create a View, I believe a type keyword is automatically attached to it (this is true in the UI, at least).
You can do something like this with your query string to filter out views:
the_query = "NOT typekeywords:View Service AND owner:youruser"
Or, in your loop you can use Item.typeKeywords to isolate views if you need to do further manipulations. The typeKeywords property for a view should be equal to a list like so:
['ArcGIS Server', 'Data', 'Feature Access', 'Feature Service', 'Service', 'Singlelayer', 'Hosted Service', 'View Service']
So, you can do: if "View Service" in item.typeKeywords do this or that.