Result Type Rules and Display Templates with SharePoint Hybrid Search

I have a client who is transitioning from SharePoint on-premises search to hybrid search with Office 365 and SharePoint Online. They are looking forward to removing several servers from their farm that are currently dedicated to the Indexing and Content Processing roles. They plan to collapse their Search Topology down to two redundant crawlers. This simpler topology is one of the big benefits of Hybrid Search with the SharePoint Cloud Index. Of course, the other big benefit is now you only have one index for all for your content. That single index is served to both your Office 365 Search Center and Delve as well as the on-premises search center. I teach all of this in my class SharePoint and Office 365 Hybrid Workloads, which I teach as a 3-day hands-on online training course and an abbreviated version as a workshop at conferences. (The next one will be in Haarlem, Netherlands October 24th at SharePoint Unite and in Orlando, FL at SPLive 360, November 12th.)

Up and Running

The first two steps to getting Hybrid Search running are to create a Cloud Search Service Application and run the on-boarding process either with PowerShell or the recently released Hybrid Picker option. The next step is to create Result Sources on premises that tell your local farm to get the query results from a Remote SharePoint source. We configured the remote address of the tenant, saved the new Result Source, marked it as Default and that’s it. Now you can go to your on-premises Search Center and execute a query.

Hybrid Search Configuration Rule #1: Create Result Sources on premises that reference your SharePoint Online Tenant.

Note: If it does not work it may be due to the Default Result Source not getting picked up by your Search Results Web part picking up the Default setting. You can fix this by editing the web part and setting the correct Result Source.

The issues began to arise when they tried to apply Result Type rules to render their custom Display Templates. They assumed that the rules should be created on premises since the Display Templates are in the site collection Master Page catalog of the local site collection. This assumption was supported because they could pick their custom Managed Properties in the on-premises rules picker. (As I said, they were migrating, so the custom properties had been migrated to the new on-premises search schema.) The rules were not displaying the Display Template. If we forced the Display Template in the Web part it worked fine.

Troubleshooting

My first step was to replicate the issue on a new Office 365 tenant and clean SharePoint environment. This is where I confirmed my first assumption.

Hybrid Search Configuration Rule #2: Create Managed Properties and manage Search Schema in SharePoint Online tenant.

This means that your result type rules need to be configured in your tenant too. Since they are scoped at the site collection or site and the rules may reference Managed Properties, I chose to create a test rule pointing to a test Display Template (with Ruby in bold) in my SharePoint Online Search Center (tenant.sharepoint.com/search).

Hybrid Search Configuration Rule #3: Define Result Type Rules in a SharePoint Online Search Center.

This worked fine and I saw the results below.

Sample Result Display Template

The next bit took some thinking. If my Result Type Rules are running in the SharePoint Online Search Center, then I needed to change the Result Source to reference that Site so that the remote query would cause the rule to run. The problem is that the resulting result type rule is returning a ~sitecollection relative reference to the Display Template. I can see this in the JavaScript trace.

Code inspector showing relative URL

The solution was to keep the relative path the same and add only the published Display Template to the on-premises Search Center. To ensure that the local Display Template was in use versus the “Ruby” version from SharePoint Online, I changed the label in the Display Template. Do not rename your template file.

Resolved Display Template

To be clear here, all I did on premises, after fixing the Remote Result Source (see updated Rule #1 below), was add the Display Template to the local Master Page Gallery. I did not create a local Result Type Rule, in fact, I could not because the Managed Properties don’t exist in the on-premises Search Schema. So here is the clarified Rule #1.

(Updated) Hybrid Search Configuration Rule #1: Create Result Sources on premises that reference your SharePoint Online Tenant Site where you configured the Result Type Rules.

To be clear, we changed the URL of the Remote Service URL to point to the SharePoint Online Search Center since that is where we had configured the Result Type Rules. This is what the Result Type Rule looks like.

Search Site Reference in Result Type rule

Here is a summary of where Brian and I have been able to successfully configure the different parts of SharePoint Hybrid Search.

Feature SharePoint Online SharePoint On-Premises
Content Sources N/A Cloud SSA
Search Schema Tenant No1
Result Sources Tenant – Consumed Online SSA – Consumed On-Premises
Query Rules Tenant, Site Collection, Site2    Cloud SSA, Site Collection, Site2
Result Types Site Collection3 No1
Search Usage Reports    Site Collection No4
Query Suggestions Tenant No4
Authoritative Pages Tenant5 No4
Crawl Log N/A Cloud SSA

Conclusion

I hope this helps you to understand the chain of events that occur and how to get your rules running on your Hybrid Farms. I put together this diagram to make it a little clearer. It is my interpretation of the query flow.

Relationship diagram for what to confiure where

Special thanks for Neil Hodgkinson (@NellyMo) and Brian Pendergrass (@bspndr) for looking over my shoulder on this post and providing valuable content for the table of features. All errors are my own.


  1. You can perform these actions, but they have no effect [return]
  2. On-Prem Query Rules are processed first. Online Query Rules are processed ONLY if no On-Prem rules were triggered. [return]
  3. Custom Display Templates must exist locally relative to current Site Collection. [return]
  4. I have not tested these, but would not expect these to work [return]
  5. Authoritative Pages only effective if a Non-Default Rank Model where the “Clickdistance” feature is enabled. [return]
|| Hybrid || People Who Rock || Search || SharePoint 2013 || SharePoint 2016 || SharePoint Online

comments powered by Disqus

Let's Get In Touch!


Ready to start your next project with us? That’s great! Give us a call or send us an email and we will get back to you as soon as possible!

+1.512.539.0322