HELP with NEST FluentAPI create Parent-Child Mapping on existing index

I found a way how to create Parent-Child Mapping on existing index using direct request to server
Parent-Child Mapping,
but i don't find any example how to do it using Fluent API, is it possible ?

PS I use ES 5.4.0 and .NET client

Yes it's possible. We don't currently have an example of this in the client documentation but the integration tests contain an example. In it

  1. Each King has a list of other Kings who are the foes of the King.
  2. A King has n Prince children
  3. Each Prince has n Duke children
  4. Each Duke has n Earl children
  5. Each Earl has n Baron children

So, we have four descending Parent/Child relationships. The id to use for each document is the Name property on the document.

public interface IRoyal
{
    string Name { get; set; }
}

[ElasticsearchType(IdProperty = "Name")]
public abstract class RoyalBase<TRoyal> : IRoyal
    where TRoyal : class, IRoyal
{
    public string Name { get; set; }
}

public class King : RoyalBase<King>
{
    public List<King> Foes { get; set; }
}

public class Prince : RoyalBase<Prince> { }
public class Duke : RoyalBase<Duke> { }
public class Earl : RoyalBase<Earl> { }
public class Baron : RoyalBase<Baron> { }

var client = new ElasticClient();

var createIndexResponse = client.CreateIndex("royals", c => c
				.Mappings(map => map
					.Map<King>(m => m
						.AutoMap()
						.Properties(props => props
							.Keyword(s => s
								.Name(p => p.Name)
							)
							.Nested<King>(n => n
								.Name(p => p.Foes)
								.AutoMap()
							)
						)
					)
					.Map<Prince>(m => m
						.AutoMap()
						.Properties(props => props
							.Keyword(s => s
								.Name(p => p.Name)
							)
						)
						.Parent<King>()
					)
					.Map<Duke>(m => m
						.AutoMap()
						.Properties(props => props
							.Keyword(s => s
								.Name(p => p.Name)
							)
						)
						.Parent<Prince>()
					)
					.Map<Earl>(m => m
						.AutoMap()
						.Properties(props => props
							.Keyword(s => s
								.Name(p => p.Name)
							)
						)
						.Parent<Duke>()
					)
					.Map<Baron>(m => m
						.AutoMap()
						.Properties(props => props
							.Keyword(s => s
								.Name(p => p.Name))
						)
						.Parent<Earl>()
					)
				 )
			);

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