Restrict search to a specific site using REST API

cancel
Showing results for 
Search instead for 
Did you mean: 
vezance
Member II

Restrict search to a specific site using REST API

We are using Alfresco CE 5.2. Using the REST API for Search, we want to restrict the search to a particular site only. Going through the Search API details on the API explorer page, we did not find any details on how to restrict search to one site. 

We also tried the following solution provided by someone else:

{
"query": {
"language": "afts",
"query": "=PARENT:<node ID> AND =name:'<search query>'"
}
}

However, this did not return any results for us. 

Is there a way to use the REST API to search within a specific site or folder?

6 Replies
mehe
Senior Member II

Re: Restrict search to a specific site using REST API

Add SITE:<sitename> to your query:

"query": "SITE:<sitename> ..."

or the folder to search within as "ANCESTOR":

"query": "ANCESTOR:\"workspace://SpacesStore/...\""

Regards,

Martin

vezance
Member II

Re: Restrict search to a specific site using REST API

The one with 'SITE' did not work for us.

When you say <sitename>, do I just mention the site name e.g. 'My First Site', or something else?

The 'ANCESTOR' one worked, though. Thanks.

mehe
Senior Member II

Re: Restrict search to a specific site using REST API

the site name should be the "short name" or "id" of the site. The one that's also used in the url to the site.

vezance
Member II

Re: Restrict search to a specific site using REST API

We tried that too e.g. 'my-first-site'. That didn't work either.

mehe
Senior Member II

Re: Restrict search to a specific site using REST API

I had testsite and it worked, maybe you have to put it in quotes when the string contains "-" :

"query":"SITE:\"my-first-site\""

vezance
Member II

Re: Restrict search to a specific site using REST API

That worked perfectly. Thanks Martin.