Azure Search Sitecore Custom Index

No comments

If you are looking to convert your Lucene or Solr custom indexes to Azure Search indexes – then this sample Azure search custom index configuration will help you to quickly alter them.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <contentSearch>
            <!-- REINDEX ON PUBLISH END SINGLE INSTANCE
             This strategy is triggered on publish:end and uses the EventQueue to incrementally rebuild the index. The strategy contains all indexes which belong to it. 
        -->
            <onPublishEndAsyncSingleInstance type="Sitecore.ContentSearch.Maintenance.Strategies.OnPublishEndAsynchronousSingleInstanceStrategy, Sitecore.ContentSearch" singleInstance="true">
                <param desc="database">web</param>
                <!-- Whether or not a full index rebuild should be triggered when the number of items in the EventQueue exceeds the number specified 
               in ContentSearch.FullRebuildItemCountThreshold. -->
                <CheckForThreshold>true</CheckForThreshold>
            </onPublishEndAsyncSingleInstance>

            <indexConfigurations>
			<!-- Name of customIndex			-->
                <sample.azure.CustomSearchConfiguration ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration" >
                    <initializeOnAdd>true</initializeOnAdd>

                    <!-- DEFAULT FIELD MAPPING
               The field map allows you to have full control over the way your data is stored in the index. This affects the way data is queried, 
               the performance of searching, and the way that data is retrieved and cast to a proper type in the API. 
          -->
                    <fieldMap ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration/fieldMap">
                        <fieldNames hint="raw:AddFieldByFieldName">
                            <field fieldName="_uniqueid"            storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
                            </field>
                        </fieldNames>
                    </fieldMap>
                    <documentOptions type="Sitecore.ContentSearch.DocumentBuilderOptions, Sitecore.ContentSearch">

                        <!-- 
						NOTE: Azure Search can ONLY store upto 1000 Fields
						This flag will index all fields by default. This allows new fields in your templates to automatically be included into the index.
               You have two choices :                
               1) Set this to 'true' and place all the fields that you would like to remove in the 'ExcludeField' list.
               2) Set to false and place all fields you would like to be indexed in the 'IncludeField' list below.
            -->
                        <indexAllFields>false</indexAllFields>

                        <!-- GLOBALLY EXCLUDE TEMPLATES FROM BEING INDEXED
                 This setting allows you to exclude items that are based on specific templates from the index.
            -->
                        <exclude hint="list:AddExcludedTemplate">
                            <BucketFolderTemplateId>{ADB6CA4F-03EF-4F47-B9AC-9CE2BA53FF97}</BucketFolderTemplateId>
                            <SearchTemplateId>{319CDB61-AC60-42FF-9178-D3CF751FE4F9}</SearchTemplateId>
                        </exclude>

                        <!-- GLOBALLY INCLUDE TEMPLATES IN INDEX
                 This setting allows you to only include items that are based on specific templates in the index. You must specify all the
                 templates that you want to include, because template inheritance is not checked. 
                 When you enable this setting, all the items that are based on other templates are excluded, regardless of whether the template
                 is specified in the ExcludeTemplate list or not.
            -->
                        <include hint="list:AddIncludedTemplate">
                            <TestTemplateID>{91FA9CBD-02D8-44F5-8F27-AA1EDA0D703F}</TestTemplateID>
                        </include>

                        
                        <!-- COMPUTED INDEX FIELDS 
               This setting allows you to add fields to the index that contain values that are computed for the item that is being indexed.
               You can specify the storageType and indextype for each computed index field in the <fieldMap><fieldNames> section.
            -->
                        <fields hint="raw:AddComputedIndexField">
                            <field fieldName="TestComputedField" storageType="no" indexType="tokenized">Sc.Foundation.Search.TestComputedField,Sc.Foundation.Search</field>
                        </fields>

                    </documentOptions>


                </sample.azure.CustomSearchConfiguration>
            </indexConfigurations>
			<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
                <indexes hint="list:AddIndex">
				<!-- Note: Update the Index name below  -->
                    <index id="sample_azure_index" type="Sitecore.ContentSearch.Azure.CloudSearchProviderIndex, Sitecore.ContentSearch.Azure">
                        <param desc="name">$(id)</param>
                        <param desc="connectionStringName">cloud.search</param>
                        <param desc="totalParallelServices">5</param>
                        <!-- This initializes index property store. Id has to be set to the index id -->
                        <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
                        <configuration ref="contentSearch/indexConfigurations/sample.azure.CustomSearchConfiguration">
                            <scoringProfilesRepository ref="contentSearch/scoringProfilesRepository" />
                        </configuration>
                        <schemaBuilder ref="contentSearch/searchServiceSchemaBuilder" />
                        <searchService type="Sitecore.ContentSearch.Azure.Http.CompositeSearchService, Sitecore.ContentSearch.Azure" />
                        <strategies hint="list:AddStrategy">
                            <!-- NOTE: order of these is controls the execution order -->
                            <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsyncSingleInstance" />
                        </strategies>
                        <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
                            <policies hint="list:AddCommitPolicy">
                                <policy type="Sitecore.ContentSearch.ModificationCountCommitPolicy, Sitecore.ContentSearch">
                                    <Limit>1000</Limit>
                                </policy>
                            </policies>
                        </commitPolicyExecutor>
                        <locations hint="list:AddCrawler">
                            <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                                <Database>web</Database>
								<!-- Note: Update the root path and Database based on Sitecore Instance Type  -->
                                <Root>/sitecore/content/sample_items</Root>
                            </crawler>
                        </locations>
                        <enableItemLanguageFallback>true</enableItemLanguageFallback>
                        <enableFieldLanguageFallback>true</enableFieldLanguageFallback>
                    </index>
                </indexes>
            </configuration>
        </contentSearch>
    </sitecore>
</configuration>


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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.