Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

AEM Querybuilder API giving different result compare to Query debugger/query performance tool

Avatar

Level 2

Hi All,

 

Recently we have upgraded our system to 6.3 to 6.5. When we execute query using Querybuilder API it is giving double when compare with query execution with Query debugger/query performance tool. It is giving blank values when we use Querybuilder API.It is picking proper custom index also ,in our 6.3 instance it is giving proper result. 

 

For instance, when i execute query 

Query debugger/query performance tool(/libs/granite/operations/content/diagnosistools/queryPerformance.html) - the result is 145 in total

Querybuilder API giving result - 290 in total result for same query. out of which 145 it is giving proper result 145 with blank records.

 

Please help me what might be causing the issue.

 

Regards,

Guru Pavan

1 Accepted Solution

Avatar

Correct answer by
Employee

Do you use the exact same syntax in the queryPerformance and in query builder? Does it employ the same index in both cases?

View solution in original post

13 Replies

Avatar

Correct answer by
Employee

Do you use the exact same syntax in the queryPerformance and in query builder? Does it employ the same index in both cases?

Avatar

Level 2
Yes I have used same syntax and same properties ,values,groups. Both the cases it is picked same index . As mentioned earlier only difference is with Query builder API I am getting double result, out of that half of the result is empty records.

Avatar

Employee

Try reindexing that index. It helped resolve the case for one of my customers. They had somewhat similar scenario of migration from 6.3 to 6.5 and issues in retrieving the correct number of records using the QueryBuilder API with their custom index.

Avatar

Level 2
Actually when 6.3 to 6.5 upgrade done, same time reindex triggered and succeeded. I will do once again reindexing?

Avatar

Employee

I also remember something. They had to make some changes according to QueryBuilder API for 6.5 to get the desired results.

Avatar

Level 2
Can you please provide exact details QueryBuilder API for 6.5

Avatar

Community Advisor

If it doesn't help, could you please share your Query from we-retail section?

Try same in AEM vanilla instance as well. It seems issue could be with instance.



Arun Patidar

Avatar

Level 2
Hi Arun, Thank you. I have tried executing query in other AEM 6.5 upgraded instance as well same issue exists. Only with QueryBuilder API I am getting the issue.

Avatar

Community Advisor
we are also using QueryBuilder in 6.5.1 & 6.5.4 but we did not see that issue. Can you please confirm the version and if possible can you share the QueryBuilder API code, not the complete code just the Query forming part and APIs. So that I can cross check the approach.


Arun Patidar

Avatar

Level 2
Hi Arun, Currenly we are using AEM 6.5.2 and uber jar version is Uber-jar-6.5.0. Please find query forming code. @reference protected QueryBuilder queryBuilder; Map<String, String[]> filteredQueryParamMap = new HashMap<String, String[]>(); Query query = this.queryBuilder.createQuery(PredicateGroup.create(filteredQueryParamMap), session); result = query.getResult(); filteredQueryParamMap.put("100_group.p.or", new String[] { "true" }); filteredQueryParamMap.put("100_group." + requiredPropertyKey, new String[] { "jcr:content/@myproject:onTime" }); filteredQueryParamMap.put("100_group." + requiredPropertyValueKey, new String[] { "true" }); filteredQueryParamMap.put("100_group." + requiredPropertyOperationKey, new String[] { "exists" }); filteredQueryParamMap.put("100_group.100_property.property", new String[] { "jcr:content/@ myproject:offTime" }); filteredQueryParamMap.put("100_group.100_property.value", new String[] { "true" }); filteredQueryParamMap.put("100_group.100_property.operation", new String[] { "exists" });

Avatar

Community Advisor

Hi,

I tried your code and it gives me same results as UI

Here is the complete code - https://github.com/arunpatidar02/aem63app-repo/blob/master/java/SimpleQueryAPISearchServlet.java

 

Map<String, String[]> filteredQueryParamMap2 = new HashMap<>();

			filteredQueryParamMap2.put("type", new String[]{"cq:Page"});
			filteredQueryParamMap2.put("path", new String[]{"/content/we-retail"});
			filteredQueryParamMap2.put("group.1_property", new String[]{"jcr:content/@jcr:created"});
			filteredQueryParamMap2.put("group.1_property.operation", new String[]{"exists"});
			filteredQueryParamMap2.put("group.2_property", new String[]{"jcr:content/@cq:lastModified"});
			filteredQueryParamMap2.put("group.2_property.operation", new String[]{"exists"});
			filteredQueryParamMap2.put("group.p.or", new String[]{"true"});
			filteredQueryParamMap2.put("p.limit", new String[]{"-1"});

			Query query = queryBuilder.createQuery(PredicateGroup.create(filteredQueryParamMap2), session);
			SearchResult result = query.getResult();
			logger.info("Result node {}", result.getTotalMatches());

 

 



Arun Patidar