"Conflict between type..." error when using Azure Search provider


Description

If there are two or more fields with the same name but different types that need to be indexed, this causes issues with Azure Search. In this case, Sitecore field types are mapped to different Azure Search Edm types. As a result, when rebuilding an index, Sitecore XP tries to add values of different types to the same field, which is not supported by Azure and causes a conflict between the type of the incoming field and the field in the schema. The following error is logged:

FATAL Could not add field {3C05A626-A3B1-4CBC-BF67-198537A13E20} : default value for indexable sitecore://web/{1514EA8F-E397-4443-A29D-722D99E33493}?lang=en&ver=1 
Exception: System.ApplicationException 
Message: Conflict between type of incomming field 'Edm.Boolean' and field in schema 'Edm.String' 
Source: Sitecore.ContentSearch.Azure 
  at Sitecore.ContentSearch.Azure.Schema.CloudSearchIndexSchemaBuilder.AddFields(IndexedField[] fileds) 
  at Sitecore.ContentSearch.Azure.Schema.CloudSearchIndexSchemaBuilder.AddField(String fieldName, Object fieldValue) 
  at Sitecore.ContentSearch.Azure.CloudSearchDocumentBuilder.AddField(String fieldName, Object fieldValue, Boolean append) at Sitecore.ContentSearch.AbstractDocumentBuilder`1.CheckAndAddField(IIndexable indexable, IIndexableDataField field)

Solution 1

If the conflicting field does not belong to any of the system templates, you can rename it so that the fields have unique names.

Solution 2

Configure Sitecore XP to index only one of the fields with the same name. This means that only the values of the chosen field are indexed and available for search.

To implement this solution:

  1. Choose one of the fields from the fields with same name that you want to be indexed.
  2. Add the other field ID to the index field exclude list:
    • To exclude the field for all indexes, add it to the default index configuration:
      sitecore\contentSearch\indexConfigurations\defaultCloudIndexConfiguration\documentOptions\exclude hint="list:AddExcludedField"
    • To exclude it from a specific index (core, master, and so on), add it to the configuration corresponding to this index:
      sitecore\contentSearch\configuration\indexes\indexid="index_name"\configuration\documentOptions\exclude hint="list:AddExcludedField"

Note: You can also create a new index in Sitecore XP configuration and perform the above steps for the other field from the fields with the same name. This allows you to index both field values but in different indexes.