Can someone please let me know on how to fetch the nodes that are present under /content ? I need to know the query.
Solved! Go to Solution.
Hi,
The following is the AEM query in java to fetch all the nodes under /content path.
Sample code:
Map predicateMap = new HashMap();
//path predicate is used to search under a particular hierarchy ("/content" here)
map.put("path", "/content");
//type predicate is used for searching particular nodetype only
//map.put("type", "cq:Page"); (It will search only cq:Page nodes under /content)
//map.put("type", "nt:file"); (It will search only nt:file nodes under /content)
//map.put("type", "sling:Folder"); (It will search only cq:Page nodes under /content)
//nodename predicate is used to search exact nodenames for the result set
//map.put("nodename","HomePage"); (It will search for HomePage node under /content)
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);
//Get search results
SearchResult result = query.getResult();
//Iterate query results
for (Hit hit : result.getHits()) {
// Write your logic here
}
NOTE: Please customize the above query to fetch the nodes under /content as per your requirement.
By default, the query builder json servlet displays a maximum of 10 hits. Adding the following parameter allows the servlet to display all query results:
map.put("p.limit", "-1");
Please refer the links below for more details:
http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/
https://hashimkhan.in/2015/12/02/query-builder/
http://aemcq5.blogspot.in/2014/11/cq5-querybuilder-simplified.html
We hope this helps!
Regards,
Hi,
Use query debugger to get the nodes under /content give the property of node you want to search and the path you want to search.
"http://hostname:port/libs/cq/search/content/querydebug.html"
Below URL provides you details required.
http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/
Thanks
Views
Replies
Total Likes
You can go for sql2 query also. following links might help. they have many sample query. generate yours as needed.
Hi,
The following is the AEM query in java to fetch all the nodes under /content path.
Sample code:
Map predicateMap = new HashMap();
//path predicate is used to search under a particular hierarchy ("/content" here)
map.put("path", "/content");
//type predicate is used for searching particular nodetype only
//map.put("type", "cq:Page"); (It will search only cq:Page nodes under /content)
//map.put("type", "nt:file"); (It will search only nt:file nodes under /content)
//map.put("type", "sling:Folder"); (It will search only cq:Page nodes under /content)
//nodename predicate is used to search exact nodenames for the result set
//map.put("nodename","HomePage"); (It will search for HomePage node under /content)
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);
//Get search results
SearchResult result = query.getResult();
//Iterate query results
for (Hit hit : result.getHits()) {
// Write your logic here
}
NOTE: Please customize the above query to fetch the nodes under /content as per your requirement.
By default, the query builder json servlet displays a maximum of 10 hits. Adding the following parameter allows the servlet to display all query results:
map.put("p.limit", "-1");
Please refer the links below for more details:
http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/
https://hashimkhan.in/2015/12/02/query-builder/
http://aemcq5.blogspot.in/2014/11/cq5-querybuilder-simplified.html
We hope this helps!
Regards,