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

**URL:** <https://discuss.elastic.co/t/help-with-nest-fluentapi-create-parent-child-mapping-on-existing-index/90248>\
**Category:** Elasticsearch\
**Created:** [June 21, 2017, 9:16am UTC](https://discuss.elastic.co/t/help-with-nest-fluentapi-create-parent-child-mapping-on-existing-index/90248 "2017-06-21T09:16:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitry\_Bolshakov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmitry_bolshakov/32/18527_2.png) [@Dmitry\_Bolshakov](https://discuss.elastic.co/u/Dmitry_Bolshakov)\
**Post date:** [June 21, 2017, 9:16am UTC](https://discuss.elastic.co/t/help-with-nest-fluentapi-create-parent-child-mapping-on-existing-index/90248/1 "2017-06-21T09:16:28Z")

</div>

I found a way how to create Parent-Child Mapping on _ **existing** _ index using direct request to server  
[Parent-Child Mapping](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child-mapping.html),  
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

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [June 23, 2017, 9:10am UTC](https://discuss.elastic.co/t/help-with-nest-fluentapi-create-parent-child-mapping-on-existing-index/90248/2 "2017-06-23T09:10:01Z")

</div>

Yes it's possible. We don't currently have an example of this in the [client documentation](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html) but the[integration tests contain an example](https://github.com/elastic/elasticsearch-net/blob/5.x/src/Tests/Search/Request/InnerHitsUsageTests.cs). 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>()
					)
				 )
			);
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 21, 2017, 9:10am UTC](https://discuss.elastic.co/t/help-with-nest-fluentapi-create-parent-child-mapping-on-existing-index/90248/3 "2017-07-21T09:10:32Z")

</div>

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