cancel
Showing results for 
Search instead for 
Did you mean: 

Getting all grandchildredn of node in one query

slawek
Champ in-the-making
Champ in-the-making

Hello,

Is it possible to get all grandchildren (or even grand...grandchildren) of node using just one query? I'm using REST API and Alfresco Community v5.2.0.

Thank you

Slawek

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

At the same time as you I provided the alternative variant using ANCESTOR. Both are valid / possible. ANCESTOR has a slight advantage over PATH in the cost of processing.

Also note that the PATH example is a bit simple for the stated use case. A proper example query for PATH and looking up children + grand-children would be:

PATH:"/app:company_home/cm:My_x0020_Folder//*"

The above retrieves all children and grand-children of a folder called "My Folder" located at the top level of the Repository. If that folder had the NodeRef workspace://SpacesStore/1234-567890-3457-aefd, the ANCESTOR variant would look like this:

ANCESTOR:"workspace://SpacesStore/1234-567890-3457-aefd"

The resolution of the wildcards and // in the PATH query is what typically makes it more expensive than ANCESTOR.

View answer in original post

3 REPLIES 3

angelborroy
Community Manager Community Manager
Community Manager

Alfresco provides different languages to specify queries. You can learn more at

Search query syntax APIs | Alfresco Documentation 

https://docs.alfresco.com/5.2/concepts/query-lang-support.html

In your case, I'd use a PATH query with AFTS syntax. Something similar to this:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '{
"query": {
"language": "afts",
"query": "PATH:\"/\""
}
}' 'http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search'
Hyland Developer Evangelist

afaust
Legendary Innovator
Legendary Innovator

At the same time as you I provided the alternative variant using ANCESTOR. Both are valid / possible. ANCESTOR has a slight advantage over PATH in the cost of processing.

Also note that the PATH example is a bit simple for the stated use case. A proper example query for PATH and looking up children + grand-children would be:

PATH:"/app:company_home/cm:My_x0020_Folder//*"

The above retrieves all children and grand-children of a folder called "My Folder" located at the top level of the Repository. If that folder had the NodeRef workspace://SpacesStore/1234-567890-3457-aefd, the ANCESTOR variant would look like this:

ANCESTOR:"workspace://SpacesStore/1234-567890-3457-aefd"

The resolution of the wildcards and // in the PATH query is what typically makes it more expensive than ANCESTOR.

afaust
Legendary Innovator
Legendary Innovator

You can perform a FTS query using ReST API to query for nodes using the ANCESTOR field. This will give you all /^(grand-)*children$/ of a particular node.