【问题标题】:Elasticsearch C# NEST IndexMany ChildrenElasticsearch C# NEST IndexMany Children
【发布时间】:2017-01-07 03:33:31
【问题描述】:

我在使用 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)));

child 和 parent 共享相同的 Id 整数。

我没有收到错误,但孩子永远不会被索引,并且文档永远不会被添加到总索引计数中。

单独为它们编制索引工作

    foreach (var child in IenumerableOfChild
            {

                client.Index(child, descriptor => descriptor
                 .Parent(child.Id.ToString()).Index("myindex"));
            }

我不想单独索引质量数量。我想使用 IndexMany 批量索引子记录。有人能指出我做错了什么吗?

【问题讨论】:

    标签: c# elasticsearch indexing parent-child nest


    【解决方案1】:

    经过进一步调查,弹性服务器返回超时。通过一次批处理 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);
                }
    

    【讨论】:

    • 很高兴您了解了它。试一试批处理大小和您可以为集群发送的并发批处理请求的数量。
    • 谢谢。我没有想到并发请求。这真是个好主意。可能是批量异步?
    • 已经有一个基于任务的BulkAsync 方法,因此您可以使用它们的集合来触发并发批量请求。查看master 中的BulkAll,了解如何实现这一点的一些想法-github.com/elastic/elasticsearch-net/blob/…。这也是它的 PR 对这个问题的一些讨论:github.com/elastic/elasticsearch-net/pull/2162
    【解决方案2】:

    您需要添加。查询的路由字段,以便将子级与父级映射。 如下所示:-

    var indexResponse = elasticService.Bulk(s => s.IndexMany<Child> 
                                          (childreslist, 
     (bulkDescriptor, record) => bulkDescriptor.Index(Constants.INDEX_NAME)
                                                                        .Type("_doc")
                                                                        .Routing(new 
                Routing(record.id.ToString()))
                                                                    ));                  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 2016-06-16
      相关资源
      最近更新 更多