[英]Elasticsearch C# NEST IndexMany Children
I'm having an issue using the bulk method in NEST to index child records into Elasticsearch. 我在使用NEST中的批量方法将子记录索引到Elasticsearch时遇到问题。
I am using ElasticSearch 2.3.5 and NEST 2.4.4 我使用的是ElasticSearch 2.3.5和NEST 2.4.4
I've mapped an index as such: 我已经映射了一个索引:
myindex
{
"mappings": {
"elasticparent": {},
"elasticchild": {
"_parent": {
"type": elasticparent
}
}
}
}
And I've indexed the parent objects using the IndexMany method: 我使用IndexMany方法索引了父对象:
client.IndexMany<elasticparent>(batch, "myindex");
This all works well. 这一切都运作良好。
I would now like to index the children using IndexMany . 我现在想使用IndexMany为孩子编制索引。 Here's what I've tried so far: 这是我到目前为止所尝试的:
client.Bulk(s => s.IndexMany(IenumerableOfChild,
(bulkDescriptor, record) =>
bulkDescriptor.Index("myindex").Type("elasticchild").Parent(record.Id)));
The child and parent share the same Id integer. 子和父共享相同的Id整数。
I don't get an error, but the children never get indexed and the documents are never added to the total indexed count. 我没有收到错误,但子项永远不会被索引,文档永远不会添加到总索引计数中。
Indexing them individually works : 单独编制索引可以 :
foreach (var child in IenumerableOfChild
{
client.Index(child, descriptor => descriptor
.Parent(child.Id.ToString()).Index("myindex"));
}
I don't want to index mass amounts individually. 我不想单独索引质量数量。 I would like to use IndexMany to bulk index the child records. 我想使用IndexMany批量索引子记录。 Can someone point out what I'm doing wrong? 有人可以指出我做错了吗?
After further investigation, the Elastic Server was returning a timeout. 经过进一步调查后,Elastic Server返回了超时。 By batching the requests to 1000 items at a time, it is now working properly! 通过一次将请求批量处理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);
}
You need to add. 你需要添加。 The routing field to the query in order to map the child with parent. 查询的路由字段,以便将子映射到父级。 Like this below:- 如下所示: -
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.