November Happy Hour will be moved to Thursday December 5th.

Index Job - An item with the same key has already been added.

Vote:
 

Hi, 

I have been having a strange issue where by I am getting the following error:

EPiServer.Find.Cms.ContentIndexer: EN00102: An exception occurred while indexing content [Link 87162__CatalogContent] [GUID ecfb8896-13d6-4cb8-9806-a28a58fe083d] [Type Product] [Name Test Product]: An item with the same key has already been added.
System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem item)
   at System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, TItem item)
   at EPiServer.Find.Json.DelegateContractInterceptor.ModifyContract(JsonObjectContract contract)
   at EPiServer.Find.Helpers.ListExtensions.ForEach[T](IEnumerable`1 value, Action`1 action)
   at EPiServer.Find.Json.JsonContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at EPiServer.Find.Json.JsonContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at EPiServer.Find.Api.BulkActionConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at EPiServer.Find.Json.Serializer.SerializeToTextWriter(JsonSerializer serializer, Object value, TextWriter textWriter)
   at EPiServer.Find.Json.Serializer.SerializeObjectsToJsonRequest(JsonSerializer serializer, IJsonRequest jsonRequest, IEnumerable values)
   at EPiServer.Find.Api.BulkCommand.Execute(List`1& serializationFailures)
   at EPiServer.Find.Api.BulkCommand.Execute()
   at EPiServer.Find.Cms.ContentIndexer.IndexWithRetry(IContent[] contents, Int32 maxRetries, Boolean deleteLanguageRoutingDuplicatesOnIndex)
   at EPiServer.Find.Cms.ContentIndexer.Index(IEnumerable`1 content, IndexOptions options)
   at EPiServer.Find.Cms.ContentIndexer.IndexBatch(IEnumerable`1 content, Action`1 statusAction, Int32& numberOfContentErrors, Int32& indexingCount, Boolean deleteLanguageRoutingDuplicatesOnIndex)
As I understand, when we are indexing product the batch contains duplicates, however I am unable to explain why it has duplicates, would anyone know?
Thanks
Paul
#230045
Oct 28, 2020 21:12
Vote:
 

It looks like a problem with the conventions. Do you have any extension methods for your content model? 

#230067
Oct 29, 2020 8:13
Vote:
 

It looks like a problem with the conventions. Do you have any extension methods for your content model? 

#230068
Oct 29, 2020 8:13
Vote:
 

Hi Quan,

Yes, we are using extension methods to index extra data on the commerce products, things like size, style, pricing, etc.

Do you suggest disabling the conventions and running the job without the conventions to see if that will resolve the issue?

Thanks

Paul

#230069
Oct 29, 2020 9:03
Vote:
 

Yes - that is something to try. You can also post your extension methods here so I and other poster can see if we can spot anything 

#230070
Oct 29, 2020 9:06
Vote:
 

Hi Quan,

Thanks for your help after much trial and error removing and adding conventions, it came down to the following 3 conventions:

SearchClient.Instance.Conventions.ForInstancesOf<ProductOne>().IdIs(x => x.CatalogId);
SearchClient.Instance.Conventions.ForInstancesOf<ProductTwo>().IdIs(x => x.CatalogId);
SearchClient.Instance.Conventions.ForInstancesOf<ProductThree>().IdIs(x => x.CatalogId);

Previously we were not indexing the catalog products, variants and nodes. After enabling these to be indexed and removing the above conventions the error message has disappeared.

Thanks

Paul

#230077
Oct 29, 2020 12:16
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.