NEST/Elasticsearch.Net version: 6.0.0
Elasticsearch version: 6.2.0
I try to create parent/child relationship like here: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/parent-child-relationships.html
I created three classes: one base class and two derived classes:
public class BaseEntity
{
public JoinField MyJoinField { get; set; }
public string Id { get; set; }
}
public class ParentEntity: BaseEntity
{
[Text]
public string BillNumber { get; set; }
}
public class ChildEntity: BaseEntity
{
[Text]
public string ChildData { get; set; }
[Keyword(Index = false)]
public string ExtraData { get; set; }
}
And created CreateIndexDescriptor for create index and add mapping:
var descriptor = new CreateIndexDescriptor(indexTypeInfo.IndexName.ToLowerInvariant())
.Settings(s => s
.RefreshInterval(refreshIntervalInMilliseconds)
.NumberOfShards(numberOfShards)
.NumberOfReplicas(numberOfReplicas))
.Mappings(ms => ms
.Map<TDocument>(m => m
.RoutingField(r => r.Required())
.AutoMap<TParent>()
.AutoMap<TChild>()
.Properties(props => props
.Join(j => j
.Name(indexTypeInfo.JoinField)
.Relations(r => r
.Join<TParent, TChild>()
)
)
)
));
indexTypeInfo is an object of class, that has information about indexing type like index name, index type, name of join field.
It works as expected, index and mapping are correctly created, but I have problems how to use it: I can index and search only BaseEntities and it fails to be casted to type ChildEntity or type ParentEntity. I want to extract not only Id and MyJoinField but BillNumder for parents or ChildData for children.
In your documentation I haven’t found any examples how to search parents or children(just HasParent/HasChild query but without example what answer elastic returns).
Also, your documentation says that I can create parent child relationship without base class, for example, I can create two classes:
public class ParentEntity: BaseEntity
{
public JoinField MyJoinField { get; set; }
public string Id { get; set; }
[Text]
public string BillNumber { get; set; }
}
public class ChildEntity: BaseEntity
{
public JoinField MyJoinField { get; set; }
public string Id { get; set; }
[Text]
public string ChildData { get; set; }
[Keyword(Index = false)]
public string ExtraData { get; set; }
}
In this situation I don’t understand how to create mapping: what type I should specify in method Map(…) when I create mapping and what type I should specify in methods like Index, Update, Get etc.?