Skip to content

Exception on mapping/index create with multiple childs to the same parent: An item with the same key has already been added. : #2992

@ghost

Description

NEST/Elasticsearch.Net version: 6.0.0-beta1

Elasticsearch version: 6.1.1

CreateIndex throws an "An item with the same key has already been added." argument exception when trying to configure the mapping for multiple childs having the same parent.

Steps to reproduce:

  1. Define one parent and two child documents with a base document including the JoinField
  2. Use AutoMap for the parent and childs.
  3. Additionally configure the parent/child relation, following the documentation on https://github.com/elastic/elasticsearch-net/blob/master/src/Tests/ClientConcepts/HighLevel/Mapping/ParentChildJoins.doc.cs.
  4. CreateIndex throws "An item with the same key has already been added." argument exception.

Snippet:

var index = client.CreateIndex(
	indexName,
	s => s.Settings(x => x
		.NumberOfShards(1)
		.NumberOfReplicas(0)
	)
	.Mappings(ms => ms

		.Map<SampleBase>(mx => mx
			.AutoMap<SampleParent>()
			.AutoMap<SampleChildOne>()
			.AutoMap<SampleChildTwo>()
			.Properties(props => props
				.Join(j => j
					.Name(p => p.MyJoinField)
					.Relations(r => r
						.Join<SampleParent, SampleChildOne>()
						.Join<SampleParent, SampleChildTwo>()
					)
				)
			)
		)
	)
);

See also source:
SameKeyIndexProblem.txt

Exception:

Error: 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 Nest.Relations.Add(RelationName type, Children children)
   at Nest.IsADictionaryDescriptorBase`4.<>c__DisplayClass1_0.<Assign>b__0(TInterface a)
   at Nest.DescriptorPromiseBase`2.Assign(Action`1 assigner)
   at Nest.IsADictionaryDescriptorBase`4.Assign(TKey key, TValue value)
   at Nest.RelationsDescriptor.Join[TParent,TChild]()
   at SameKeyErrorProblem.Program.<>c.<Main>b__0_6(RelationsDescriptor r) in Program.cs:line 63
   at Nest.JoinPropertyDescriptor`1.<>c__DisplayClass5_0.<Relations>b__0(IJoinProperty a)
   at Nest.Fluent.Assign[TDescriptor,TInterface](TDescriptor self, Action`1 assign)
   at Nest.DescriptorBase`2.Assign(Action`1 assigner)
   at Nest.JoinPropertyDescriptor`1.Relations(Func`2 selector)
   at SameKeyErrorProblem.Program.<>c.<Main>b__0_5(JoinPropertyDescriptor`1 j) in Program.cs:line 61
   at Nest.PropertiesDescriptor`1.SetProperty[TDescriptor,TInterface](Func`2 selector)
   at Nest.PropertiesDescriptor`1.Join(Func`2 selector)
   at SameKeyErrorProblem.Program.<>c.<Main>b__0_4(PropertiesDescriptor`1 props) in 
Program.cs:line 60
   at Nest.TypeMappingDescriptor`1.<>c__DisplayClass86_0.<Properties>b__0(ITypeMapping a)
   at Nest.Fluent.Assign[TDescriptor,TInterface](TDescriptor self, Action`1 assign)
   at Nest.DescriptorBase`2.Assign(Action`1 assigner)
   at Nest.TypeMappingDescriptor`1.Properties(Func`2 propertiesSelector)
   at SameKeyErrorProblem.Program.<>c.<Main>b__0_3(TypeMappingDescriptor`1 mx) in Program.cs:line 56
   at Nest.MappingsDescriptor.Map[T](Func`2 selector)
   at SameKeyErrorProblem.Program.<>c.<Main>b__0_2(MappingsDescriptor ms) in Program.cs:line 54
   at Nest.CreateIndexDescriptor.<>c__DisplayClass14_0.<Mappings>b__0(ICreateIndexRequest a)
   at Nest.Fluent.Assign[TDescriptor,TInterface](TDescriptor self, Action`1 assign)
   at Nest.CreateIndexDescriptor.Mappings(Func`2 selector)
   at SameKeyErrorProblem.Program.<>c.<Main>b__0_0(CreateIndexDescriptor s) in Program.cs:line 50
   at Nest.Extensions.InvokeOrDefault[T,TReturn](Func`2 func, T default)
   at Nest.ElasticClient.CreateIndex(IndexName index, Func`2 selector)
   at SameKeyErrorProblem.Program.Main(String[] args) in Program.cs:line 48

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions