Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Querying for Nodes, only first level

Avatar

Former Community Member

I'm query my jcr:content for nodes with a certain resource type, however, the query returns ALL nodes under the matched queries. When I iterate over the results with results.getHits(), it iterates all nodes. I only want one level deep from the jcr:content node that I'm searching. I've attempted using "p.nodedepth" with a value of "1", but this doesn't do anything. Any direction would be appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Using JCR SQL -- you can use this syntax:
String sql= "SELECT * FROM nt:unstructured WHERE jcr:path LIKE '"+path +"/%' AND NOT jcr:path LIKE '"+path +"/%/%'";

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Using JCR SQL -- you can use this syntax:
String sql= "SELECT * FROM nt:unstructured WHERE jcr:path LIKE '"+path +"/%' AND NOT jcr:path LIKE '"+path +"/%/%'";

Avatar

Former Community Member

How would I write this using the QueryBuilder notation?