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
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
n
Prince childrenn
Duke childrenn
Earl childrenn
Baron childrenSo, 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.
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.