Sitecore Computed index and custom fields added only for custom index in multi Azure index Environment


We have a requirement to create custom azure index with some computed fields, so I have created the custom index(site_master_index) and added the computed fields, but this sitecore instance is a multi-site, so adding computed field should only needs to be added to my newly created index instead of adding to all the indexes.

Steps followed to create this index and computed field in Azure.

  • Add a patch file for creating computed fields and that will be only added to our newly created index.
  • Create the patch by inheriting from contentSearch/indexConfigurations/defaultCloudIndexConfiguration in the newly created patch file.
<?xml version="1.0"?>

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
            <sitecore>
                        <contentSearch>
                                    <indexConfigurations>
                                                <customSiteConfiguration
                                                            ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration ">
                                                            <fieldMap ref="contentSearch/indexConfigurations/defaultCloudIndexConfiguration/fieldMap">
                                                                        <fieldNames hint="raw:AddFieldByFieldName">
                                                                                    <field type="System.String" fieldName="title" searchable="YES" retrievable="YES" facetable="YES" filterable="YES" sortable="YES" boost="1f" settingType="Sitecore.ContentSearch.Azure.CloudSearchFieldConfiguration, Sitecore.ContentSearch.Azure" cloudAnalyzer="language"/>
                                                                        </fieldNames>
                                                            </fieldMap>
                                                            <documentOptions type="Sitecore.ContentSearch.Azure.CloudSearchDocumentBuilderOptions,Sitecore.ContentSearch.Azure">
                                                                        <fields hint="raw:AddComputedIndexField">
                                                                                
                                                                                    <field fieldName="thumbnailurl">EMAAR.Emaarcommunities.Foundation.Indexing.ComputedFields.ThumbnailUrl, EMAAR.Emaarcommunities.Foundation.Indexing</field>
                                                                                    <field fieldName="pageurl">EMAAR.Emaarcommunities.Foundation.Indexing.ComputedFields.PageUrl, EMAAR.Emaarcommunities.Foundation.Indexing</field>
                                                                                    <field 
                                                                        </fields>
                                                            </documentOptions>
                                                </customSiteConfiguration>
                                    </indexConfigurations>
                        </contentSearch>  
</sitecore>
</configuration>

  • Create custom index where we need this computed index field to be get added.
  • Add the above defined computed fields to the custom index patch configuration file created.
  • Using ref keyword(inherit) the parameters and settings from the computed index patch file created in the xpath contentSearch/indexConfigurations/customSiteConfiguration
<sitecore role:require="Standalone or ContentManagement" search:require="Azure">
                    <contentSearch>
                              <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
                                        <indexes hint="list:AddIndex">
                                                  <index id="site_master_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/customSiteConfiguration" />
                                                            <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/syncMaster" />
                                                            </strategies>
                                                            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
                                                                      <policies hint="list:AddCommitPolicy">
                                                                                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
                                                                                <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>master</Database>
                                                                                <Root>/sitecore/content/sitecontent</Root>
                                                                      </crawler>
                                                            </locations>
                                                            <enableItemLanguageFallback>false</enableItemLanguageFallback>
                                                            <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
                                                  </index>
                                        </indexes>
                              </configuration>
                    </contentSearch>
          </sitecore>
  • Publish these config files and do indexing from sitecore and then now we will able to see new computed fields created in Azure index.
Note:
Index name should be in lower case.
Happy indexing 😊



Comments

Popular posts from this blog

Custom Item Url and resolving the item in Sitecore - Buckets

Fixing Sitecore Buckets folder path - Items created after 12 AM server time zone

Sitecore Search - API Crawler with Edge Pagination