Sample Queries

These samples are given in Java™ properties style notation. To use them with the Java™ API, use a Java™ HashMap as in the API sample that follows.

For the QueryBuilder JSON Servlet, each example includes a link to your local CQ installation (at the default location, http://localhost:4502). Log in to your CQ instance before using these links.

CAUTION
By default, the query builder json servlet displays a maximum of ten hits.
Adding the following parameter allows the servlet to display all query results:
p.limit=-1
NOTE
To view the returned JSON data in your browser, you may want to use a plugin such as JSONView for Firefox.

Returning all results

The following query return ten results (or, to be precise, a maximum of ten), but inform you of the Number of hits: that are available:

http://localhost:4502/bin/querybuilder.json?path=/content&1_property=sling:resourceType&1_property.value=foundation/components/text&1_property.operation=like&orderby=path

path=/content
1_property=sling:resourceType
1_property.value=foundation/components/text
1_property.operation=like
orderby=path

The same query (with the parameter p.limit=-1) will return all results (this might be a high number depending on your instance):

http://localhost:4502/bin/querybuilder.json?path=/content&1_property=sling:resourceType&1_property.value=foundation/components/text&1_property.operation=like&p.limit=-1&orderby=path

path=/content
1_property=sling:resourceType
1_property.value=foundation/components/text
1_property.operation=like
p.limit=-1
orderby=path

Using p.guessTotal to return the results

The purpose of the p.guessTotal parameter is to return the appropriate number of results that can be shown by combining the minimum viable p.offset and p.limit values. The advantage of using this parameter is improved performance with large result sets. This avoids calculating the full total (for example, calling result.getSize()) and reading the entire result set, optimized all the way down to the Oak engine & index. This can be a significant difference when there are 100 thousands of results, both in execution time and memory usage.

The disadvantage to the parameter is users do not see the exact total. But you can set a minimum number like p.guessTotal=1000 so it will always read up to 1000, so you get exact totals for smaller result sets, but if it is more than that, you can only show “and more”.

Add p.guessTotal=true to the query below to see how it works:

http://localhost:4502/bin/querybuilder.json?path=/content&1_property=sling:resourceType&1_property.value=foundation/components/text&1_property.operation=like&p.guessTotal=true&orderby=path

path=/content
1_property=sling:resourceType
1_property.value=foundation/components/text
1_property.operation=like
p.guessTotal=true
orderby=path

The query returns the p.limit default of 10 results with a 0 offset:

"success": true,
"results": 10,
"total": 10,
"more": true,
"offset": 0,

As of AEM 6.0 SP2, you can also use a numeric value to count up to a custom number of maximum results. Use the same query as above, but change the value of p.guessTotal to 50:

http://localhost:4502/bin/querybuilder.json?path=/content&1_property=sling:resourceType&1_property.value=foundation/components/text&1_property.operation=like&p.guessTotal=50&orderby=path

It returns a number the same default limit of ten results with a 0 offset, but will only display a maximum of 50 results:

"success": true,
"results": 10,
"total": 50,
"more": true,
"offset": 0,