简体   繁体   English

如何在 ElasticSearch NEST 7.x 中使用 doc id 索引文档列表

[英]How to index list of documents with doc id in ElasticSearch NEST 7.x

I'm indexing a list item with this code:我正在使用以下代码索引列表项:

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

How to make IndexMany or any equivalent call so that I can index many items in one shot with their Ids.如何进行 IndexMany 或任何等效调用,以便我可以使用它们的 ID 一次性索引许多项目。

You can use the low level API elasticsearch.net to bulk indexing many documents specifying index and id.您可以使用低级 API elasticsearch.net 对许多指定索引和 id 的文档进行批量索引。

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

It worked this way:它是这样工作的:

 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;
             }
         ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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