Using the arcgis python API, is it possible to restrict search results to exact matches by title?
My query is title:City_Boundaries and owner:username and the search is returning other "City_Boundary" matches and would like to restrict to exact matches.
I reviewed this search documentation and could not find anything related to exact matches
I had same issue. I solved the issue by adding search field as sort field and sorted on ascending order, then took the first one in the list. It worked for me. ,
#you can try something like:
item_to search ="your item to search"
owner ="owner of the item"
item=gis.content.search(query="title:"+ item_to search + " AND owner: " + owner, sort_field='title', sort_order='asc' )[0]
Surendran
I agree you should be able to search for an exact match. I want to search by the name, for example, Golf_Course and get the ID so I can update it. Unfortunately, the first one it finds is a similarly named layer. Updating data requires an exact match, it seems strange that finding an exact match would not have been the default
Please vote on the following idea to have an exact match option.
Old but ran into this issue today. You can add more logic after the content.search to workaround the limitation:
searchData=gis.content.search(query='title:{} AND owner:{}'.format(name,owner))
for search in searchData:
if search["title"]==name:
#match
If you would like to sort results by whether they contain some exact string, but the string does not necessarily have to make up the entire title, you can try something like this:
boston_data = gis.content.search(query = "title:Boston",
item_type='Feature Layer',
max_items=1000,
outside_org=True)
for item in boston_data:
if "Boston" in str(item.title):
display(item)
else:
pass
This will return only results that have the word "Boston" in them, but not limit your search results to titles that are exactly "Boston".
Portal and AGOL use Elasticsearch under the hood to store item metadata. It’s meant to do fast full text searches and returns ‘hits’. Don’t expect exact searches.
Put more conditions to your query. Limit to your organization by passing an orgid or to a user. Drop max_items to 1 too.
Getting the same question, the workaround I'm using is list comprehension. E.g :
searched_items=[item for item in gis. content.search(query="title: base_map", item_type="Map Service", max_items=20 if item.title=="base_map"]
Just what I was after! Thanks.
@ESRI how come this bug reported back to almost 5 years ago still not fixed. is it that hard or just not listening to your users. very disappointed