How To Setup A Coveo Search Hub

And Why You Should Do It

March 9, 2022

By David Austin

One item often overlooked when setting up your Coveo organization is the use of the Search Hub. It's vital however if you are going to utilize Analytics but it does so much more.

Why Bother?

For one, it allows you to identify, if you have multiple search interfaces, which search interface the query originates from. It also allows you to create a condition-based query pipeline based upon the search hub, leverage Coveo ML, and as mentioned, filter data in your analytics reporting.

How To Set Coveo Search Hub Up

In the past, we would explicitly state the Query Pipeline in the initialization. And depending on your implementations, you would then have to programmatically change it if you needed to use a different one.

There are three ways we can go about setting up the Search Hub. They are all valid, but one way is more secure than the others.

  • Configuring the Search Endpoint
  • Configuring the Analytics Component
  • Configuring the Search Token (Recommended)

Now, while one way is recommended over the others, you may not have the ability to do it (depending on the implementation), hence why there are multiple ways to configure it. The important thing to understand is that in both the Search Endpoint setup and the Analytics component setup, it's technically feasible to have this altered or tampered with. Updating the Search Token prevents this from happening (hence the recommendation).

Let's walk through each method.

Configuring The Search Endpoint

If you are using the API Key method of authenticating and you're not looking to use the CoveoAnalytics component then this is the approach you should take. For example: setting up a standalone search box.

To do it, locate your initialization script, which likely looks like the following, and update the queryStringArguments to include searchHub.

document.addEventListener("DOMContentLoaded", () => {
    Coveo.SearchEndpoint.configureCloudV2Endpoint(
      "abccompanyorganization",
      "xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "https://platform.cloud.coveo.com/rest/search",
      {
        "queryStringArguments": {
          "searchHub": "ABCCompanyMainSearch"
        }
      });
  })

In this method, it's important that the API Key used only as appropriate access.

Configuring The Analytics Component

Perhaps the simplest way to go about updating the searchHub is by adding it to the CoveoAnalytics component.

To do this locate, or add your CoveoAnalytics component and add in the data-search-hub attribute.

<div class="CoveoAnalytics" data-search-hub="ABCCompanyMainSearch"></div>

Configuring The Search Token (Recommended)

This is only possible if you're using search token authentication, so if you're not you'll need to look at the other options. Typically you'll be using search token authentication if you have users logged in and some if not all of your content is secured in some fashion.

If you want to understand more about it, you can read up on it here.

To configure the Search Hub as part of the token, you'll want to add it into the JSON payload shown below.

{
    "searchHub": "ABCCompanyMainSearch",
    "userIds": [
      {
        ...
      }
    ]
  }

The JWT token that returns as part of the authentication method will contain the searchHub information.

Note: If you're using Coveo for Salesforce the search token method is used and the search hub is already part of it.

Configure Your Query Pipeline To Use Search Hubs

Log into the Platform Admin and select Query Pipelines. For each query pipeline that you have, you will want to repeat these steps.

On the right, click Create a new condition.

Coveo Query Pipelines CustomQP Overview Screen

Then create the condition where Search Hub is the desired value.

Coveo Search Hub Add A Condition Screen

Click Add condition and then save your query pipeline. Once done, you will have properly enabled Coveo Analytics and the Coveo Machine Learning capabilities.

Image of Fishtank employee David Austin

David Austin

Development Team Lead | Sitecore Technology MVP x 3

David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.