Hi @aravind2407
To achieve the requirement of retrieving only one document for each type using the AEM Query Builder, you can't directly set a limit per group within a single query since the Query Builder does not support this functionality out of the box. However, you can still accomplish your goal by running separate queries for each type, each with a limit of 1. This ensures that you get one document per type.
Here's how you would set up separate queries:
// Query for type1
path=/content/dam/documents
type=dam:Asset
1_property=jcr:content/metadata/dc:format
1_property.value=application/pdf
2_property=@jcr:content/metadata/documentType
2_property.value=type1
p.limit=1
orderby=@publishDate
orderby.sort=desc
// Query for type2
path=/content/dam/documents
type=dam:Asset
1_property=jcr:content/metadata/dc:format
1_property.value=application/pdf
2_property=@jcr:content/metadata/documentType
2_property.value=type2
p.limit=1
orderby=@publishDate
orderby.sort=desc
// Query for type3
path=/content/dam/documents
type=dam:Asset
1_property=jcr:content/metadata/dc:format
1_property.value=application/pdf
2_property=@jcr:content/metadata/documentType
2_property.value=type3
p.limit=1
orderby=@publishDate
orderby.sort=desc
In these queries, p.limit=1 is set for each separate query to ensure that only one result is returned for each document type. The orderby=@publishDate and orderby.sort=desc parameters will ensure that the most recently published document of each type is returned.
Running these queries separately and combining the results will give you one document for each type as required. This approach is the most straightforward way to bypass the limitation of the AEM Query Builder in not being able to specify per-group limits within a single query.
If you are implementing this within a Java service or an OSGi component, you can programmatically execute these queries one after the other and aggregate the results. If your use case requires this to be done frequently or at scale, you might consider implementing a custom service that abstracts this logic away, so you don't have to manually run and manage multiple queries each time.
For more detailed information, you can refer to the official documentation on the Query Builder API and Predicate Reference:
- Query Builder API: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/developing/full-stack/search/query-builder-api.html?lang=en
- Query Builder Predicate Reference: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/developing/full-stack/search/query-builder-predicates.html?lang=en