Limiting fields returned by Search in Oracle Commerce Cloud

Gregory Eschbacher
Oracle Developers
Published in
3 min readMay 25, 2019

In Oracle Commerce Cloud, results retrieved from /ccstoreui/v1/search or /ccstoreui/v1/assembler will typically bring back all of the fields associated with that record.

If your application has many custom product type properties, however, this might be returning too much data, especially since all you typically want is enough to render the page.

There might also be fields that you consider private data, such as margin or quantity sold.

By editing the search services, you can specify a white-list of fields that you want to be returned (and all others will be ommitted in the response). This also has the benefit of reducing the payload (although with compression and caching, typical /search or /assembler responses are under 150kb).

This might be very useful for making the product typeahead responses much smaller.

Accessing the default search config

Out of the box, the search service that handles configuration for search results is located at /gsadmin/v1/cloud/pages/Default/services/guidedsearch. Configuration for the OOTB typeahead is located at /gsadmin/v1/cloud/pages/Default/services/typeahead.

The pattern we will follow is:

  • GET /gsadmin/v1/cloud/pages/Default/services/guidedsearch
  • modify the JSON
  • PUT /gsadmin/v1/cloud/pages/Default/services/guidedsearch

Specifying the field lists

The JSON returned from the /guidedsearch endpoint will contain a section called “resultsList”. By default, it should look something like this:

"resultsList": {
"@type": "ResultsList",
"rankingRules": {
"merchRulePaths": ["/content/rankingRules"],
"systemRulePaths": ["/content/system/rankingRules"],
"systemRuleLimit": 10
}
},

What we will do is add new configuration into the “resultsList” section.

Note that in Oracle Commerce Cloud sites, we index records at the SKU level, and then Search “rolls” them up into product records. For instance, you’ll see this configuration in the @appFilterState section:

"rollupKey": "sku.listingId"

When it comes to limiting the fields returned, there are two places we can configure this: “attributes” and “childRecordAttributes”. Most likely, you are going to limit fields using “childRecordAttributes”. Only a few product-level fields are controlled by “attributes”, such as the min/max price.

In the JSON below, I show how to configure the response to only include name and description.

"resultsList": {
"@type": "ResultsList",
"rankingRules": {
"merchRulePaths": ["/content/rankingRules"],
"systemRulePaths": ["/content/system/rankingRules"],
"systemRuleLimit": 10
},
"childRecordAttributes" : ["product.description", "product.displayName"]
},

In reality, returning ONLY those 2 fields would not be enough, but the short list is good for demonstration purposes.

NOTE: This is a white list, and for now, there is no way to specify a black list. This means if your application was returning 70 fields and you wanted to omit 2, it requires you to specify a list of 68 fields.

PUT the updated configuration

Once you have modified the JSON, PUT the entire block of JSON retrieved from /guidedsearch or /typeahead back to /gsadmin/v1/pages/Default/services/guidedsearch (or /typeahead).

At this point, your changes will be viewable in your preview Storefront. Log into OCC Admin and the updated field list is what will be returned. You can also execute GET

This allows you to see if reducing the fields has broken parts of your storefront.

Invoke publishing to promote the changes to your Storefronts

Once you have verified the JSON payload in your Preview Storefront, we need to promote those changes so they affect your live Storefronts.

POST /ccadmin/v1/search/index?op=partial

Conclusion

I hope you find this quick article useful. Make sure to “follow” me on Medium, as I plan on writing more short quick articles.

--

--

Gregory Eschbacher
Oracle Developers

technologist, Oracle Cloud architect, commerce specialist