HOW TO

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

Last Published: June 29, 2022

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')

Article ID:000024383

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS API for Python 1 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic