Azure index error

Faye Spath asked on December 8, 2022 15:59

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.

Recent Answers


Juraj Ondrus answered on December 9, 2022 09:32

What version and hotfix are you using? Are you able to reproduce the issue on a clean Kentico installation? If yes, what are the steps?
What are the search field mappings set for your page types? Isn't it possible you have added the field to some page type and it has different data type or search settings?

0 votesVote for this answer Mark as a Correct answer

Marcel Vriend answered on December 9, 2022 10:27

You can try to delete the search index from the Azure Search service and then rebuild it in Kentico.

0 votesVote for this answer Mark as a Correct answer

Faye Spath answered on December 9, 2022 14:30

I found out yesterday it is happening on multiple projects not just this one. I am not able to reproduce it locally. it is only happening on the production server. I did verify that the page types were not adding that field in somewhere. we are on hotfix version 13.0.78

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 12, 2022 08:54

If it works locally, what is the difference when compared to the production project? Project files, DB records?

0 votesVote for this answer Mark as a Correct answer

Jeroen Fürst answered on December 12, 2022 15:14

Hi Faye,

Have you tried rebuilding the index? That usually fixes it for me.

Cheers, Jeroen

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.