Can NEST index multiple documents to a data stream?

The IndexMany method has no way to specify the op_type. And the Bulk method doesn't seem to provide any configuration for op_type either.

Documents can be bulk indexed to a data stream with the bulk API

var client = new ElasticClient();

var docs = new [] 
	new { Name = "foo", Value = "bar" },
	new { Name = "foo2", Value = "bar2" },
	new { Name = "foo3", Value = "bar3" },

var bulkResponse = client.Bulk(b => b

which yields the following request

POST /my-data-stream/_bulk?refresh=true

If you have many documents to index to a data stream, I'd recommend using the bulk observable to do so

// some function that lazily enumerates documents
IEnumerable<object> GetDocs()
	yield return new { Name = "foo", Value = "bar" };
	yield return new { Name = "foo2", Value = "bar2" };
	yield return new { Name = "foo3", Value = "bar3" };

var bulkAllObservable = client.BulkAll(GetDocs(), d => d
	.BufferToBulk((desc, docs) => desc.CreateMany(docs))

var waitHandle = new ManualResetEvent(false);
ExceptionDispatchInfo exceptionDispatchInfo = null;

var observer = new BulkAllObserver(
	onNext: response =>
		// do something e.g. write number of pages to console
	onError: exception =>
		exceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception);
	onCompleted: () => waitHandle.Set());


Thanks. The Bulk methods seems to have already covered the op_type setting. Hope this could be mentioned somewhere in the documentation.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.