如何在ElasticSearch NEST 7.x中为具有文档ID的文档列表编制索引

问题描述 投票:0回答:2

我正在使用以下代码索引列表项:

foreach (var menu in mappedCollection)
        {
            var response = await client.IndexAsync(menu, i => i.Id(menu.OptomasToolId));
        }

如何进行IndexMany或任何等效的调用,以便我可以用它们的ID一口气将很多项目编入索引。

c# elasticsearch nest
2个回答
0
投票

您可以使用低级API elasticsearch.net来对许多指定索引和ID的文档进行批量索引。

请参阅:https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/elasticsearch-net-getting-started.html#_bulk_indexing


0
投票

以这种方式工作:

 BulkAllObservable<MenuForElasticSearch> bulk = client.BulkAll(mappedCollection, b => b
          .BufferToBulk((descriptor, list) =>
          {
              foreach (var item in list)
              {
                  descriptor.Index<MenuForElasticSearch>(bi => bi
                      .Index(index)
                      .Id(item.OptomasToolId)
                      .Document(item)
                  );
              }
          }));
         bulk.Subscribe(new BulkAllObserver(
             onError: (e) => {
                 // TO DO;
             },
             onCompleted: () => { 
                 // TO DO;
             }
         ));
© www.soinside.com 2019 - 2024. All rights reserved.