繁体   English   中英

Elasticsearch C#NEST Index很多孩子

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM