Elasticsearch C# NEST 索引很多孩子

P L*_*Lab 7 c# indexing parent-child elasticsearch nest

我在使用NEST 中的批量方法子记录索引到 Elasticsearch 时遇到问题。

我正在使用 ElasticSearch 2.3.5 和 NEST 2.4.4

我已经映射了一个索引:

    myindex
    {
     "mappings": {
       "elasticparent": {},
        "elasticchild": {
          "_parent": {
            "type": elasticparent
          }
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

我已经使用IndexMany方法索引了父对象:

    client.IndexMany<elasticparent>(batch, "myindex");
Run Code Online (Sandbox Code Playgroud)

这一切都很好。

我现在想使用IndexMany索引孩子。这是我迄今为止尝试过的:

     client.Bulk(s => s.IndexMany(IenumerableOfChild,
                                  (bulkDescriptor, record) =>
                                  bulkDescriptor.Index("myindex").Type("elasticchild").Parent(record.Id)));
Run Code Online (Sandbox Code Playgroud)

子级和父级共享相同的 Id 整数。

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

单独索引它们是有效的

    foreach (var child in IenumerableOfChild
            {

                client.Index(child, descriptor => descriptor
                 .Parent(child.Id.ToString()).Index("myindex"));
            }
Run Code Online (Sandbox Code Playgroud)

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

P L*_*Lab 5

经过进一步调查,弹性服务器返回超时。通过一次将请求批量处理到 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);
            }
Run Code Online (Sandbox Code Playgroud)

  • 已经有一个基于任务的“BulkAsync”方法,因此您可以使用它们的集合来触发并发批量请求。看看“master”中的“BulkAll”,了解如何实现这一点的一些想法 - https://github.com/elastic/elasticsearch-net/blob/52541d0a472b6be85f5fe5d966374655671a3d37/src/Nest/Document/Multiple/BulkAll/Elastic -BulkAll.cs。这也是它的 PR 对这个问题进行了一些讨论:https://github.com/elastic/elasticsearch-net/pull/2162 (2认同)