06-19-2018 07:51 AM
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
06-20-2018 04:04 AM
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.
06-20-2018 04:00 AM
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'
06-20-2018 04:04 AM
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.
06-20-2018 04:00 AM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.