Tuesday, June 19, 2018

Sitecore Experience Commerce - Queries to debug whats in a search index

When debugging an issue with the front-end (storefront) site in a Sitecore Experience Commerce instance, it often becomes necessary to see what is in the search index. As an example I have had to check if a given category is appearing along with various sellable items which should appear inside it.

There is a difference on the query if you are using SOLR or Azure Search and I have provided both examples.

Index structure

It's worth noting that in an experience commerce instance there are several indexes which may need to be investigated and they each server as different sources of truth.
  • CatalogItemsScope - this index is used by the commerce engine role(s) along with the business tools for commerce.
  • mysite_web_index - used by the management (CM) servers.
  • fsni_master_index - used by the delivery servers (CD) to drive the front-end (storefront).
Note that index names may slightly vary based on your implementation.


To query SOLR

To query a SOLR index, you can open up the web administration, select the relevant index (purple box below), submit your query (red box below) and see if there are results (blue box below).

Querying commerce data in SOLR

To query Azure Search

To query an Azure Search index, you simply open the index in the Azure portal and use the search explorer to submit a query (red box below) and view any results (blue box below).

Querying commerce data in Azure Search

Categories

The following queries can be used to query a given category and the category ID can be obtained from the business tools.

Category ID visible in the business tools
In CatalogItemsScope - commerce engine index
Azure Search
"Entity-Category-MyCatalog-Bread Rolls  Buns"&searchFields=entityid
SOLR
entityid:"Entity-Category-MyCatalog-Bread Rolls  Buns"
In web/master indexes- Sitecore website
Azure Search
"Entity-Category-MyCatalog-Bread Rolls  Buns"&searchFields=catalogentityid
SOLR
catalogentityid_t:"Entity-Category-MyCatalog-Bread Rolls  Buns"

By commerce entity type

When debugging what commerce data is actually in the index, it's often handy to search based on the commerce entity type. Examples of types which I query on are:
  • SellableItem
  • Category
  • Catalog
In web/master indexes- Sitecore website
Azure Search
"SellableItem"&searchFields=commercesearchitemtype
SOLR
commercesearchitemtype_t:"SellableItem"

Conclusion

The above post gives some details on which search index you would want to query to debug a given issue along with some query samples for both Azure Search and SOLR. These queries can then be modified to query other fields (such as the Sitecore ID visible in the content editor interface. 

No comments:

Post a Comment