[英]Elasticsearch C# NEST IndexMany Children
我在使用NEST中的批量方法將子記錄索引到Elasticsearch時遇到問題。
我使用的是ElasticSearch 2.3.5和NEST 2.4.4
我已經映射了一個索引:
myindex
{
"mappings": {
"elasticparent": {},
"elasticchild": {
"_parent": {
"type": elasticparent
}
}
}
}
我使用IndexMany方法索引了父對象:
client.IndexMany<elasticparent>(batch, "myindex");
這一切都運作良好。
我現在想使用IndexMany為孩子編制索引。 這是我到目前為止所嘗試的:
client.Bulk(s => s.IndexMany(IenumerableOfChild,
(bulkDescriptor, record) =>
bulkDescriptor.Index("myindex").Type("elasticchild").Parent(record.Id)));
子和父共享相同的Id整數。
我沒有收到錯誤,但子項永遠不會被索引,文檔永遠不會添加到總索引計數中。
單獨編制索引可以 :
foreach (var child in IenumerableOfChild
{
client.Index(child, descriptor => descriptor
.Parent(child.Id.ToString()).Index("myindex"));
}
我不想單獨索引質量數量。 我想使用IndexMany批量索引子記錄。 有人可以指出我做錯了嗎?
經過進一步調查后,Elastic Server返回了超時。 通過一次將請求批量處理1000個項目,它現在正常工作!
foreach (IEnumerable<object> batch in objects.Batch(1000))
{
var indexResponse = client.Bulk(s => s.IndexMany(batch,
(bulkDescriptor, record) =>
bulkDescriptor.Index("myindex").Parent(record.Id.ToString()).Document(record).Type("elasticchild").Id(record.Id.ToString())));
Console.WriteLine(indexResponse);
}
你需要添加。 查詢的路由字段,以便將子映射到父級。 如下所示: -
var indexResponse = elasticService.Bulk(s => s.IndexMany<Child>
(childreslist,
(bulkDescriptor, record) => bulkDescriptor.Index(Constants.INDEX_NAME)
.Type("_doc")
.Routing(new
Routing(record.id.ToString()))
));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.