Bare Minimum Azure Search Configuration

April 12, 2017

Blog | Development | Bare Minimum Azure Search Configuration
Bare Minimum Azure Search Configuration by developer John Rappel

What are the best practices when it comes to Azure Search Configuration? When it comes to a custom Sitecore index, it is best practice to start with the bare minimum in regards to configuration files and settings.  A custom index has two primary pieces – the index declaration and the index configuration.  Regardless of the chosen search provider, Sitecore comes prepackaged with the default files required to stand up a new index.  These files will be listed in the App_Config\Include directory as:

  • Index
    • Sitecore.ContentSearch.<Provider>.Index.<Database>.config
  • Index Configuration
    • Sitecore.ContentSearch.<Provider>.DefaultIndexConfiguration.config

While it is possible to create a new index and point it at the existing DefaultIndexConfiguration, it is best practice to reference a new Index Configuration for the new index.  This way custom fields pertaining to the index are coupled with the index declaration instead of running against all indexes via the DefaultIndexConfiguration.

Azure Search is no different from Lucene or SOLR.  We can look at the existing DefaultIndexConfiguration and pull only the sections we need.  This is accomplished by referencing sections from the DefaultIndexConfiguration.  For example, instead of pulling in the entire fieldReaders section:

<fieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
 <param desc="id">defaultFieldReaderMap</param>
 <mapFieldByTypeName hint="raw:AddFieldReaderByFieldTypeName">
 <fieldReader fieldTypeName="checkbox" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.LuceneProvider.FieldReaders.CheckboxFieldReader, Sitecore.ContentSearch.LuceneProvider" />
 <fieldReader fieldTypeName="date|datetime" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.LuceneProvider.FieldReaders.DateFieldReader, Sitecore.ContentSearch.LuceneProvider" />
 <fieldReader fieldTypeName="image" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.ImageFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="single-line text|multi-line text|text|memo" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="html|rich text" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="multilist with search|treelist with search" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DelimitedListFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="checklist|multilist|treelist|treelistex|tree list" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.MultiListFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="icon|droplist|grouped droplist" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="name lookup value list|name value list" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.NameValueListFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="droplink|droptree|grouped droplink|tree" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.LookupFieldReader, Sitecore.ContentSearch" />
 <fieldReader fieldTypeName="tracking" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.NullFieldReader, Sitecore.ContentSearch" />

We instead add a reference to this section as follows:

<fieldReaders ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration/fieldReaders"/>

The same applies for a variety of sections within the config.  I have created a repository to hold a custom Azure Search index called “custom-master-index” that accounts for all of these reference sections and significantly reduces the size of the Index Configuration.  The two accompanying config files can be downloaded from this repository.  Note that I have the element indexAllFields set to false.  There are rare cases where indexing all fields is needed; by default, only index what is needed.

New fields can be added to the “AddComputedIndexField” fields section of the DocumentOptions element.  When adding new fields, if they are only added to the computed fields section, they will always be stored as strings, regardless of how they are returned.  To store as specific types, modifications need to be made to the fieldMap section- namely bringing in the default fieldMap section and adding any new fields.  The existing field mappings can be used as a guide for storing fields as arrays, dates, etc.

As mentioned previously, the same logic can be applied to Lucene and SOLR indexes.  This reduces errors surrounding indexing and has the added benefit of making upgrades the slightest bit easier to stomach.

John Rappel

.NET Practice Lead
  • Azure
  • Sitecore

Recent Work

Check out what else we've been working on