HOW TO
It is mandatory to include a tag or more when adding items in Portal for ArcGIS and ArcGIS Online. Tags are helpful in finding and identifying specific items in a portal. As more items with tags are added in the portal, it is useful to simplify tag identification. This can be done using the content.search() method in ArcGIS API for Python.
The following steps describe the workflow to search for tags in Portal for ArcGIS or ArcGIS Online, and remove duplicate tags.
from arcgis.gis import GIS import json
#for ArcGIS Online gis = GIS("https://arcgis.com", "<username>", "<password>") #for Portal for ArcGIS server_url = 'https://<machine>.<domain>.com:6443/arcgis/admin' gis = GIS('https://test.domain.com/portal', 'portaladmin', 'portal.admin') ga_server = Server(server_url, gis)
search_result = gis.content.search(query="", max_items =1000)
Note: If the max_items parameter is not specified, the default value is 10.
tagList_list = [] for tag in search_result: tagList_list.append(tag.tags) all_tags = [] for tgs in tagList_list: for t in tgs: all_tags.append(t)
all_tags.sort()
unique_tags = set(all_tags) sorted(unique_tags)
print(all_tags) print("Done")The following is a sample of the full script for ArcGIS Online.
from arcgis.gis import GIS import json gis = GIS("https://arcgis.com", "<username>", "<password>") search_result = gis.content.search(query="", max_items =1000) tagList_list = [] for tag in search_result: tagList_list.append(tag.tags) all_tags = [] for tgs in tagList_list: for t in tgs: all_tags.append(t) all_tags.sort() unique_tags = set(all_tags) sorted(unique_tags) print(all_tags)
Article ID: 000020473
Get help from ArcGIS experts
Download the Esri Support App