All searches in the Sitecore Commerce Business Tools application of one of my clients were not working and no results were returned at all. In my first blog post about Sitecore Commerce, I am going to share some knowledge that I learned about the search functionality available in Business Tools and the troubleshooting steps that I took to identify the root cause of this issue.

Business Tools Searches & Indexes

The Sitecore Commerce Business Tools is a core application in the Sitecore Commerce architecture that allows content authors to manage their e-commerce storefront. In order to simplify the access to specific e-commerce entities, the platform offers the ability for its users to perform a search in different sections.

Search box available in Merchandising, Customers and Orders sections in Business Tools.
Search box available in Merchandising, Customers and Orders sections in Business Tools.

There are three types of entities that can be searched: catalog items, customers and orders. Catalog items can be directly searched using the Search box available in the Merchandising section, but they can also be indirectly searched when configuring a promotion limited for a particular item. Customers entities and order entities can be directly searched in their respective sections as well.

Modal dialog to add a catalog item restriction to a promotion. Content typed in the Item Id field triggers a search to retrieve matching catalog items.
Modal dialog to add a catalog item restriction to a promotion. Content typed in the Item Id field triggers a search to retrieve matching catalog items.

Each searchable entity type has a corresponding search index in the search engine of choice (Solr or Azure Cognitive Search): CatalogItemsScope, CustomersScope, OrdersScope.

Because these three indexes are Sitecore Commerce indexes, they are not listed in the Sitecore Indexing Manager, where the search indexes used by the core Sitecore platform can be rebuilt. For Sitecore Commerce indexes the process to rebuild them is not accessible from a GUI in the Sitecore platform and instead requires the usage of the Postman collections included in the Sitecore Commerce release package, specifically the Run FullIndex Minion – <IndexName> requests in the SitecoreCommerce_DevOps / Minions collection.

The Commerce Minions engine is the engine responsible to manage the Sitecore Commerce indexes, automatically executing incremental indexing activities or full index rebuilds triggered via Postman.

No results in searches

The entire Business Tools search functionality was not working at all in my client solution. I started my throubleshooting investigation trying to reproduce the issue in Business Tools, searching for an entity that I knew existed in the commerce catalog. No error messages were displayed on the page, but only a message saying that no results were found.

No results message in Business Tools searches.

Any action in the Business Tools application invokes the DoUxAction() endpoint of the Commerce Authoring API service (if in the Authoring context) or of the Commerce Shops API service (if in the Shops context). I reviewed the API request associated to the search action in my browser console network section. Its response contained an error ("ResponseCode":"Error"), saying that a Solr core was not found:

{
      "MessageDate":"2020-02-16T02:48:47.435896Z",
      "Code":"Error",
      "Text":"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 404 Not Found</title>\n</head>\n<body><h2>HTTP ERROR 404</h2>\n<p>Problem accessing /solr/CatalogItemsScope/select. Reason:\n<pre>    Not Found</pre></p>\n</body>\n</html>\n",
      "CommerceTermKey":""
}

The same response was also returned when invoking the same request using Action requests available in the SearchApiSample Postman collection. The Postman collections included in the Sitecore Commerce release package are a great troubleshooting tools to directly communicate with the commerce engines, decoupling the API requests from the Business Tools application environment.

Since the Commerce Minions engine is responsible for the indexing activities for the Sitecore Commerce indexes, I also checked its logs and found the following errors:

00046 15:42:47 ERROR CtxMsg.Error.IndexDoesNotExist: Text=Search Index 'CatalogItemsScope' does not exist.
00046 15:42:47 ERROR PipelineAbort:Search Index 'CatalogItemsScope' does not exist.
00048 15:42:48 ERROR CtxMsg.Error.IndexDoesNotExist: Text=Search Index 'CustomersScope' does not exist.
00048 15:42:48 ERROR PipelineAbort:Search Index 'CustomersScope' does not exist.
00052 15:42:48 ERROR CtxMsg.Error.IndexDoesNotExist: Text=Search Index 'OrdersScope' does not exist.
00052 15:42:48 ERROR PipelineAbort:Search Index 'OrdersScope' does not exist.

Something was off with the index names

The Business Tools search functionality for all three types of commerce entities is configured in the PlugIn.Search.PolicySet-1.0.0.json policies configuration file of the commerce engine. If the names of the commerce indexes were not correct, this was the right file where to check.

During the Sitecore Commerce installation process, the name of each commerce index is generated with the following format:

<SearchIndexPrefix> + <default_index_name>

For example, the Catalog Items index could be named as local_CatalogItemsScope, where local_ would be the SearchIndexPrefix parameter used during the installation process.

The names of the indexes were somehow got modified and they were just their default name, while the Solr core names were the original names generated during the installation process.

Why the issue occurred

The Sitecore Commerce installation process took care of creating the Solr cores for the commerce indexes and to configure the policies search file accordingly. We made the mistake of importing all policies files in source control, missing to parameterize some of the properties that contained environment specific values, like the index names. The first code deployment overrode the correct configuration files.

The index names that need to match the index core names in the search engine are defined in different variables in the PlugIn.Search.PolicySet-1.0.0.json file, three for each index:

  • SearchScopeName – For the SearchViewPolicy (Sitecore.Commerce.Plugin.Search.SearchViewPolicy type)
  • Name – For the SearchScopePolicy (Sitecore.Commerce.Plugin.Search.SearchScopePolicy type)
  • SearchScopeName – For the IndexablePolicy (Sitecore.Commerce.Plugin.Search.IndexablePolicy type)

Instead of including in source control all available policies defined in the wwwroot\data\Environments folder of the commerce engines, we should have included only the files that we knew contained custom values that we wanted to manage in source control, creating a parameterized version of them.

After updating the name of the search indexes in the Search PolicySet configuration file with the correct name values and executing a bootstrap command to import the updated policies in the Sitecore Commerce Global database, I triggered a full index rebuild via Postman. The search functionality in Business Tools was finally working!

Conclusions

In my first blog post about Sitecore Commerce I shared some knowledge that I learned about the search functionality available in Business Tools while troubleshooting an issue with its core functionality. If you experience similar issues in your commerce solution, I hope my troubleshooting approach and the steps that I performed will help you to investigate them. If you have any questions, please don’t hesitate to comment on this post.

Thank you for reading!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s