English
Continue in the app
Be The First To Get Support Updates
Want to know about the latest technical content and software updates?

How To: Find specific items using queries in the arcgis.gis module with ArcGIS API for Python

Summary

When using ArcGIS API for Python in various workflows such as Clone, Export, and so forth, it may be necessary to find specific items in ArcGIS Online or Portal for ArcGIS and perform the action on only those items. To do this, the search function in arcgis.gis module can be used. It is also possible to use different queries or a combination of queries to find and use certain items.

This article shows some examples to use queries to find items in ArcGIS Online or Portal for ArcGIS using ArcGIS API for Python.

Procedure

Examples to use query in Search function to return specific items in ArcGIS Online

  • Search for all content:
items = gis.content.search(query='')
  • Search for content by keyword:
items = gis.content.search(query='KEYWORD')
  • Search for content by owner:
items = gis.content.search(query='owner:YOUR USERNAME')
items = gis.content.search(query='NOT owner:YOUR USERNAME')
  • Search for content by owner when username is already provided as a parameter:
username = "YOUR USERNAME"
items = gis.content.search(query='owner:'+username)
items = gis.content.search(query='owner:{}'.format(username)
  • Search for Feature Layers owned by the logged-in user:
items = gis.content.search(query="owner:" + gis.users.me.username)
  • Search for content by title:
items = gis.content.search(query='title:TITLE')
  • Search for content that begin with a prefix:

items = gis.content.search(query='title:TITLE*')
  • Search for content by item type
items = gis.content.search(query='', item_type='Feature Service')
items = gis.content.search(query='', item_type='Web Map')
items = gis.content.search(query='', item_type='Web Mapping Application')
  • The following query returns both Web Maps and Web Mapping Applications
items = gis.content.search(query='', item_type='Map')
  • Search for content outside the organization (query cannot be blank)
items = gis.content.search(query='title:TITLE', outside_org=True)
  • Combine query parameters
items = gis.content.search(query='title:TITLE, owner:YOUR USERNAME', item_type='Feature Layer')
items = gis.content.search(query='title:TITLE, type:map, owner:YOUR USERNAME')

Related Information

Last Published: 6/28/2022

Article ID: 000024383

Software: ArcGIS API for Python 2.0.1, 2.0, 1.9.1, 1.9, 1.8.5, 1.8.4, 1.8.3, 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6 ArcGIS Online Current Portal for ArcGIS 10.9.1, 10.9, 10.8.1, 10.8, 10.7.1, 10.7