P.hits=selective in querybuilder | Community
Skip to main content
Level 2
June 19, 2022

P.hits=selective in querybuilder

  • June 19, 2022
  • 3 replies
  • 2725 views

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_ 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

sunil_kumar_
Level 5
June 19, 2022

@iamaemuser ,
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
Level 2
June 19, 2022

@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.

Level 2
June 19, 2022

@iamaemuserCheck 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
SantoshSai
Community Advisor
Community Advisor
June 19, 2022

Hi @iamaemuser ,

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/querybuilder-api.html?lang=en
Hope that helps!

Regards,

Santosh

Santosh Sai
Level 2
June 19, 2022

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.