Get error when indexing parent / child nodes in ElasticSearch.Net

Hi! I am trying to follow this tutorial on creating parent-child relationships between items;

https://www.elastic.co/guide/en/elasticsearch/client/net-api/master/parent-child-relationships.html

My use-case is slightly different because in the tutorial you are creating a parent relationship between items in the same index. I want to create one between two different types of object, which need to be stored in different indexes. I came up with something like this;

class MyParentType
{
	public int Id {get;set;}
	public string Data {get;set;}
	public JoinField MyJoinField { get; } = typeof(MyParentType);
}

class MyChildType
{
	public int Id {get;set;}
	public string Data {get;set;}
	public JoinField ParentJoinField { get; set; }
	
    public MyChildType(MyParentType parent)
    {
        ParentJoinField = JoinField.Link<MyChildType, MyParentType>(parent);
    }
}

public static void Main(string[] args)
{
	var connectionSettings = new ConnectionSettings(
			pool, (builtin, settings) => new JsonNetSerializer(builtin, settings,
				() => new JsonSerializerSettings { Converters = { new StringEnumConverter() } }))
		.DefaultMappingFor<MyParentType>(m => m.IndexName("parents_index"))
		.DefaultMappingFor<MyChildType>(m => m.IndexName("children_index").RelationName("parents"));
		
	var client = new ElasticClient(connectionSettings);
	
	client.CreateIndex("parents_index", c => c
		.Index<MyParentType>()
		.Mappings(m => m.Map<MyParentType>(n => n
			.RoutingField(r => r.Required())
			.AutoMap<MyParentType>())));

	client.CreateIndex("children_index", c => c
		.Mappings(m => m.Map<MyChildType>(n => n
			.RoutingField(r => r.Required())
			.AutoMap<MyChildType>()
			.Properties(props => props
				.Join(j => j
					.Name(l => l.ParentNoteJoinField)
					.Relations(r => r
						.Join<MyParentType, MyChildType>()))))));
	
	var descriptor = new BulkDescriptor();
	descriptor.IndexMany(GetSomeCollectionOfParents());
	var response = client.Bulk(descriptor);
}

However, the last line returns a failed response from Elasticsearch;

operation[0]: index returned 400 _index: parents_index _type: myparenttype _id: xyz123 _version: 0 error: Type: mapper_parsing_exception Reason: "object mapping for [myJoinField] tried to parse field [myJoinField] as object, but found a concrete value"

Could someone please point out what I am doing wrong?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.