cancel
Showing results for 
Search instead for 
Did you mean: 

Restrict search to a specific site using REST API

vezance
Champ in-the-making
Champ in-the-making

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 6

mehe
Elite Collaborator
Elite Collaborator

Add SITE:<sitename> to your query:

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

or the folder to search within as "ANCESTOR":

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

Regards,

Martin

vezance
Champ in-the-making
Champ in-the-making

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
Elite Collaborator
Elite Collaborator

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
Champ in-the-making
Champ in-the-making

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

mehe
Elite Collaborator
Elite Collaborator

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

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

vezance
Champ in-the-making
Champ in-the-making

That worked perfectly. Thanks Martin.