Hi!
I try to use parent/child relation following by this document.
I have the same classes for test: MyDocument, MyParent, MyChild.
Index creation:
var createIndexResponse = ElasticClient.CreateIndex("a_test_index", c => c
.Mappings(ms => ms
.Map<MyDocument>(m => m
.RoutingField(r => r.Required())
.Properties<MyParent>(p => p
.Scalar(x => x.Id)
.Text(t => t.Name(x => x.ParentProperty))
)
.Properties<MyChild>(p => p
.Scalar(x => x.Id)
.Text(x => x.Name(n => n.ChildProperty))
)
.Properties(props => props
.Join(j => j
.Name(p => p.MyJoinField)
.Relations(r => r
.Join<MyParent, MyChild>()
)
)
)
)
)
);
Indexing data:
var parent1 = new MyParent
{
Id = 1,
ParentProperty = "Parrent1",
MyJoinField = JoinField.Root<MyParent>()
};
var parent2 = new MyParent
{
Id = 2,
ParentProperty = "Parrent2",
MyJoinField = JoinField.Root<MyParent>()
};
ElasticClient.Index<MyDocument>(parent1, x => x.Index("a_test_index").Refresh(Refresh.True));
ElasticClient.Index<MyDocument>(parent2, x => x.Index("a_test_index").Refresh(Refresh.True));
var child1 = new MyChild
{
Id = 1,
ChildProperty = "Child1",
MyJoinField = JoinField.Link<MyChild>(1)
};
var child2 = new MyChild
{
Id = 2,
ChildProperty = "Child2",
MyJoinField = JoinField.Link<MyChild>(1)
};
var child3 = new MyChild
{
Id = 3,
ChildProperty = "Child3",
MyJoinField = JoinField.Link<MyChild>(2)
};
ElasticClient.Index<MyDocument>(child1, x => x.Index("a_test_index").Refresh(Refresh.True));
ElasticClient.Index<MyDocument>(child2, x => x.Index("a_test_index").Refresh(Refresh.True));
ElasticClient.Index<MyDocument>(child3, x => x.Index("a_test_index").Refresh(Refresh.True));
-
Why indexed only last parent document?
-
How make bulk indexing? When I try like this nothing happens (but I use such indexing without parent/child relations and it works):
protected void IndexData<T>(IReadOnlyCollection<T> data, int partSize = 0) where T: class { Exception exception = null; var waitHandle = new ManualResetEvent(false); var bulkObserver = new BulkAllObserver( onError: e => { exception = e; waitHandle.Set(); throw e; }, onCompleted: () => waitHandle.Set(), onNext: b => { } ); IBulkAllRequest<T> Selector(BulkAllDescriptor<T> x) { var result = x.Index("a_test_index").MaxDegreeOfParallelism(4).RefreshOnCompleted(); if (partSize != 0) { result = result.Size(partSize); } return result; } var cancellationTokenSource = new CancellationTokenSource(); var bulkAll = ElasticClient.BulkAll(data, Selector, cancellationTokenSource.Token); bulkAll.Subscribe(bulkObserver); waitHandle.WaitOne(); if (exception != null) { throw exception; } }