You can use the portal service to search for items. Item search is the process of querying the portal service to find users, groups, or different types of content such as maps, scenes, layers, files, services, or apps from templates and builders.
You can use content search to:
- Search for public or private items.
- Find different types of items.
- Sort search results.
- Return pages of search results.
Search parameters
To search for items, you make an HTTPS request to the portal service and use the search
operation. The search
operation supports a query string with fields, and operators, such as AND, OR, and NOT. You can perform an open search for text using the default fields or you can search for text in specific fields such as the title
, description
, or tags
. You can also specify a location to search near, or a bounding box to search in by defining the bbox
parameter.
The general steps to search for items are:
- Define the URL to the portal service:
https
.://www.arcgis.com/sharing/rest/search - Provide the text for your search. For example, "Streets", or "Elevation level".
- Define the item type for your search. For example,
Web Map
orFeature Service
. - Set the sort order for your return results.
- Any additional fields, such as tags, date created, or last modified.
URL request
https://www.arcgis.com/sharing/rest/search?<parameters>
Key parameters
Name | Description | Examples |
---|---|---|
q | The text or formatted query with text. | q="streets", q="streets AND highways", q=(title:"streets" OR description:"streets") |
sort | The primary sort field. | sortField=numviews, sortField=created, sortField=modified |
sort | Return results in ascending or descending order. | sortOrder=asc, sortOrder=desc |
Additional parameters: To refine the search further, you can use parameters such as bbox
, num
, start
, and categories
.
Query structure
Here are a some of the general rules for formatting queries:
- For an open search, specify the text at the beginning. e.g.
q="streets"
- To search specific fields, use a colon
:
after the field name. - Use double quotes
"text"
around all search text. - Capitalize all AND, OR, and NOT operators.
- Use
()
to group operators. - Use the
type
field to define the type of items to return. e.g.: type
: Web Map
For example:
https://www.arcgis.com/sharing/rest/search?f=json&q=title:"London Tube" AND type:"Web Map" AND tags:Transportation
Default fields
When searching for text in items or groups, if you do not provide fields, the following default fields are searched.
Items | Groups |
---|---|
title | title |
tags | tags |
description | description |
snippet | snippet |
tagKeywords | owner |
Code examples using key parameters
Search for text
Find any type of item with the keywords title or description.
APIs
portal = new Portal(); // Default is "https://www.arcgis.com/sharing/rest"
portal.load().then(()=>{
const query = {
query: ["title:\"Seven Natural Wonders of the World\" OR description:\"Seven Natural Wonders of the World\""]
};
portal.queryItems(query).then((response)=>{
console.log(response);
});
});
REST API
curl https://www.arcgis.com/sharing/rest/search \
-d 'q=title:"Seven Natural Wonders of the World" OR description:"Seven Natural Wonders of the World"' \
-d 'f=pjson'
Search for tags and an owner
Find items by searching for tags and an owner name.
APIs
portal = new Portal(); // Default is "https://www.arcgis.com/sharing/rest"
portal.load().then(()=>{
const query = {
query: "tags:\"USA Demographics\" AND owner:\"esri\""
};
portal.queryItems(query).then((response)=>{
console.log(response);
});
});
REST API
curl https://www.arcgis.com/sharing/rest/search \
-d 'q=tags:"USA Demographics" AND owner:"esri"' \
-d 'f=pjson'
Search for a type of item
Find items by searching for a type of item. Learn more about the types of items in items.
APIs
portal = new Portal(); // Default is "https://www.arcgis.com/sharing/rest"
portal.load().then(()=>{
const query = {
query: ["title:\"London Map\" AND type:\"Web Map\""]
};
portal.queryItems(query).then((response)=>{
console.log(response);
});
});
REST API
curl https://www.arcgis.com/sharing/rest/search \
-d 'q=title:"London Map" AND type:"Web Map"' \
-d 'f=pjson'
Search by date
Find items by searching using a range of dates.
APIs
// Date range for the search
var startDate = "2022-01-01";
var endDate = "2022-12-31";
// Construct the query URL
var queryURL = "https://www.arcgis.com/sharing/rest/search";
var queryParams = {
f: "json",
q: `modified:[${startDate} TO ${endDate}]`,
num: 10 // Specify the number of results
};
// Perform the query
esriRequest(queryURL, {
query: queryParams,
responseType: "json"
}).then(function (response) {
// Handle the response
var results = response.data.results;
console.log(results);
// You can process the results and add them to the map as needed
// For example, add a MapImageLayer with the search results
var searchLayer = new MapImageLayer({
url: results[0].url // Use the URL of the first result
});
Search for a group
Find groups by searching for a text in the title.
APIs
portal = new Portal(); // Default is "https://www.arcgis.com/sharing/rest"
portal.load().then(()=>{
const query = {
query: "title: Hikers"
};
portal.queryGroups(query).then((response)=>{
console.log(response);
});
});
REST API
curl https://www.arcgis.com/sharing/rest/community/groups \
-d 'q=title:"hikers"' \
-d 'f=pjson'
Search by extent
Find items near point or a bounding box (extent).
APIs
portal = new Portal(); // Default is "https://www.arcgis.com/sharing/rest"
portal.load().then(()=>{
const query = {
query: "snippet: food cart, type: Web Map",
extent: {
xmax: "-122.6750",
xmin: "-122.6750",
ymax: "45.5051",
ymin: "45.5051"
}
};
portal.queryItems(query).then((response)=>{
console.log(response);
});
});
REST API
curl https://www.arcgis.com/sharing/rest/search \
-d 'bbox=-122.6750,45.5051, -122.6750,45.5051' \
-d 'q="food cart" AND type:"web map"' \
-d 'f=pjson'
Code examples using SQL operators
Search for web maps created after a specific date
Find web maps created after January 1st, 2024.
specific_date = "2024-01-01"
# Perform a search for web apps created after the specified date
search_query = f"created > '{date}' AND type:'Web Mapping Application'"
results = gis.content.search(query=search_query, item_type="Web Mapping Application")
# Print the search results
print("Search Results:")
for item in results:
print(f"Web App Title: {item.title}, Item ID: {item.id}, Created Date: {item.created}")
Search for feature layers owned by a user
Find feature layers that are owned by a specifid user
owner_username = "owner_username"
# Perform a search for feature layers owned by the specified user
results = gis.content.search(query=f'type:Feature Service AND owner:{username}')
# Print the search results
print("Search Results:")
for item in results:
print(f"Item Name: {item.title}, Item ID: {item.id}, Owner: {item.owner}")
Search for web apps using tags
Find web applications based on specific tags.
tags_to_search = "Enter tags here" # Example: "visualization, analysis"
# Construct the SQL query to search for web apps with specific tags
sql_query = f"tags LIKE '%{tags}%' AND type:'Web Mapping Application'"
# Perform the search
results = gis.content.search(query=sql_query, item_type='Web Mapping Application', max_items=10) # Adjust max_items as needed
# Print the search results
print("Search Results:")
for item in results:
print(f"Web App Title: {item.title}, Web App ID: {item.id}, Tags: {item.tags}")
Search for groups with a certain access type
access_type = "public"
# Construct the SQL query to search for groups with the specified access type
sql_query = f"SELECT id, title FROM groups WHERE access='{access_type}'"
# Execute the query
results = gis.groups.search(sql_query)
# Print the search results
print("Search Results:")
for group in results:
print(f"Group Name: {group.title}, Group ID: {group.id}")
Tools
Use tools to access the portal and create and manage content for applications.
ArcGIS Enterprise
Create, manage, analyze, and share data, maps, and applications in your organization.
Portal
Create, manage, and access content and data services for applications.
Map Viewer
Create, explore, and share web maps for 2D applications.
Scene Viewer
Create, style, and explore web scenes.
Vector Tile Style Editor
Create styles for basemap and vector tile layers.
Content management tools
Create, manage, organize, and share items in a portal.
Data management tools
Import data and create hosted layers and data services. Upload and manage documents, images, and other files.
Spatial analysis tools
Perform feature and raster analysis to create new datasets with the Map Viewer.
Developer credentials tool
Create API key and OAuth 2.0 developer credentials for custom applications.
Items
Manage and share items.
ArcGIS Pro
Create, style, and explore maps and scenes.
Geoprocessing tools
Import, manage, and analyze data.