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



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

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

如何进行 IndexMany 或任何等效调用,以便我可以使用它们的 ID 一次索引许多项目。

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

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

它的工作方式是这样的:

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

最新更新