I am getting an error on my production server and I am not able to replicate it on my local. The error is: Index can not contain two search fields with the same name 'documentpublishto' but different properties.
here is my code:
private static void AfterCreatingDocument(object sender, CreateDocumentEventArgs e)
{
var customFields = AzureSearchFieldFactory.GetSearchFieldValues(e.Searchable as TreeNode) ?? new Dictionary<string, object>(0);
if (customFields.Count == 0)
{
Service.Resolve<IEventLogService>().LogWarning(nameof(AzureSearchIndexSearchModule), "100", " No Search Field Values.");
}
foreach (var field in customFields)
{
e.Document.Add(field.Key, field.Value);
}
}
private static void BuildIndex(object sender, CreateOrUpdateIndexEventArgs e)
{
foreach (var fieldDefinition in AzureSearchFieldFactory.GetCustomSearchFields())
{
var isFacetable = fieldDefinition.Key.Equals(AzureSearchFieldFactory.FIELD_CONTENTTYPE, StringComparison.OrdinalIgnoreCase);
var isSortable = fieldDefinition.Key.Equals(Constants.Search.FIELD_LASTMODIFIEDDATE,
StringComparison.OrdinalIgnoreCase);
AddFieldToIndex(e.Index, fieldDefinition.Key, fieldDefinition.Value, isFacetable, isSortable);
}
}
private static void CreatingField_After(object sender, CreateFieldEventArgs e)
{
// Make built-in CategoryIDs field facetable (Kentico does not do this by default)
if (e.Field.Name.Equals(Constants.Search.FACET_DOCUMENTCATEGORYIDS, StringComparison.OrdinalIgnoreCase))
{
e.Field.IsFacetable = true;
}
if (e.Field.Name.Equals(Constants.Search.FIELD_LASTMODIFIEDDATE, StringComparison.OrdinalIgnoreCase))
{
e.Field.IsSortable = true;
}
if (e.Field.Name.Equals(nameof(TreeNode.DocumentPublishTo), StringComparison.OrdinalIgnoreCase))
{
e.Field.IsFilterable = true;
}
if (e.Field.Name.Equals(nameof(TreeNode.DocumentPublishFrom), StringComparison.OrdinalIgnoreCase))
{
e.Field.IsFilterable = true;
}
}
I found this article with the same error https://devnet.kentico.com/questions/modified-azure-search-index-give-error-on-page-update and it looks like from the explination my code is correct. Can anyone tell me what I am missing.