Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

P.hits=selective in querybuilder

Avatar

Level 2

I am using querybuilder API in a service. I want only certain properties in result instead of complete properties on that node. So I used p.hits=selected. But in result its still giving all properties.

 

Below is query used.

queryMap.put(QUERY_PATH, path);
queryMap.put(NODE_NAME, "product");
queryMap.put(LIMIT, "-1");
queryMap.put("p.hits","selective");
queryMap.put("p.properties","categoryName");

 

Below is the code to retrieve result.

ValueMap valueMap =  hit.getProperties();
String jsonStr = gson.toJson(valueMap);

After running query, in jsonStr I could see all properties instead of what given in p.properties. 

 

@Kiran_Vedantam @Arun_Patidar @SantoshSai  @DEBAL_DAS @fanindras @lukasz-m @Pulkit_Jain_ 

 

6 Replies

Avatar

Community Advisor

@akhilathomas1 ,
Add you raw query here. To give a proper answer, need to see query. Using p.hits=selective it gives selected properties. Check simple working query.

type=cq:PageContent
path=/content/we-retail/us
p.hits=selective
p.properties=sling:resourceType jcr:title

Avatar

Level 2

@sunil_kumar_ thanks for your reply. For the query you posted as well, when I run it via querybuilder API in java, its returning complete properties. When I run it via rest API(http://localhost:4502/bin/querybuilder.json) its giving only the properties when I add in query. So the doubt I have is whether it will not work when I do this via java code.

Avatar

Level 2

@akhilathomas1Check if you have some typing error in query creation. Check your final executable query.

Same query can't give you two different result. Check this in query

p.hits=selective

Avatar

Community Advisor

Hi @akhilathomas1 As mention by other comment. Same query can't give you two different result. There must be some issue with your query. May you are not generating correct query in java. Try to print your executing query in LOG and see for any syntax issue with query.

Avatar

Community Advisor

Hi @akhilathomas1 ,

Try this,

queryMap.put(QUERY_PATH, path);
queryMap.put(NODE_NAME, "product");
queryMap.put(LIMIT, "-1");
map.put("property", "categoryName");
map.put("property.operation", "exists");
for (Hit hit : result.getHits()) {
      String path = hit.getPath();
      Resource resource = resourceResolver.getResource(path);
        Node node = resource.adaptTo(Node.class);
        // read property values
        String categoryName = node.getProperty("categoryName").getString();
        //do Something
}

Please visit for more details: https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/query-builder/quer...
Hope that helps!

Regards,

Santosh

Avatar

Level 2

yes, saw documentation of adobe now, its mention as "By default, the QueryBuilder JSON Servlet will return a default set of properties for each node in the search result (e.g. path, name, title, etc.). In order to gain control over which properties are returned, you can do one of the following:" .

so p.hits=selective will work only on QueryBuilder JSON, not when we do query with querybuiler API in backend.