Kat Ben
Kat Ben

Reputation: 1

NEST: How can I do different operations and mapping types in one bulk request?

I have a list of "event" objects. Each event has its operation (delete, update, index, etc), its mapping type (document, folder, etc.), and the actual content to be indexed into Elasticsearch, if any. I don't know what any of these operations will be in advance. How can I use NEST to dynamically choose the bulk operation and mapping type for each of these events?

Upvotes: 0

Views: 508

Answers (1)

Rob
Rob

Reputation: 9979

Bulk method on ElasticClient should fit your requirements.

You can pass various bulk operations into theBulkRequest, this is a simple usage:

var bulkRequest = new BulkRequest();
bulkRequest.Operations = new List<IBulkOperation>
{
    new BulkCreateDescriptor<Document>().Id(1).Document(new Document{}),
    new BulkDeleteDescriptor<Document>().Id(2)
};

var bulkResponse = client.Bulk(bulkRequest);

Hope it helps.

Upvotes: 0

Related Questions