コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

この会話は、活動がないためロックされています。新しい投稿を作成してください。

解決済み

Run AEM Query-builder query in batch

Avatar

Level 2

I have the below working query

path=/content/dam
type=sling:OrderedFolder
nodename=[0-9][0-9][0-9][0-9]-([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9])
property=jcr:content/metadataprofile
property.operation=exists
property.value=false
p.limit=-1

It runs on entire Path=/content/dam, so it traverse all nodes for about 20 minutes and gives results.

How can i make it in batches when using query-builder API code-wise, like - traverse 1000 nodes and do-something code-wise and then continue with query and traversing next 1000 nodes and so-on ? Is it possible ?
Thanks in advance.

トピック

トピックはコミュニティのコンテンツの分類に役立ち、関連コンテンツを発見する可能性を広げます。

1 受け入れられたソリューション

Avatar

正解者
Community Advisor
3 返信

Avatar

正解者
Community Advisor

Hi,

You can combine offset, guessTotal and limit

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/querybuilder-api.html

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 2
Should i give P.limit and p.guessTotal as some random number OR should I assign guessTotal as SearchResult.getTotalMatches() ? As i don't want my code to stop after certain number of nodes and want it to run completely without missing any nodes. Can you share sample java code using implementing that?

Avatar

Community Advisor

you should use guess Total. Always set guessTotal to true unless you know your result set. This will make the result set small and counting it will be fast.

Use offset to set starting and ending point of result set.

 

int hits = 10;
int start = 0;
int offset = 3;// for example 4th set of result.

predicateMap.put("p.guessTotal", String.valueOf(offset + (6 * hits)));
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);
if (offset >= 0) {
 start = offset;
}
query.setStart(start);
query.setHitsPerPage(hits);
Arun Patidar

AEM LinksLinkedIn