# Can NEST index multiple documents to a data stream?

**URL:** <https://discuss.elastic.co/t/can-nest-index-multiple-documents-to-a-data-stream/288949>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 11, 2021, 6:04am UTC](https://discuss.elastic.co/t/can-nest-index-multiple-documents-to-a-data-stream/288949 "2021-11-11T06:04:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![buaaytt](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@buaaytt](https://discuss.elastic.co/u/buaaytt)\
**Post date:** [November 11, 2021, 6:04am UTC](https://discuss.elastic.co/t/can-nest-index-multiple-documents-to-a-data-stream/288949/1 "2021-11-11T06:04:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [November 15, 2021, 7:39am UTC](https://discuss.elastic.co/t/can-nest-index-multiple-documents-to-a-data-stream/288949/2 "2021-11-15T07:39:34Z")

</div>

[Documents can be bulk indexed to a data stream with the bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/current/use-a-data-stream.html#add-documents-to-a-data-stream)

```auto
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
	.Index("my-data-stream")
	.Refresh(Refresh.True)
	.CreateMany(docs)
);

```

which yields the following request

```auto
POST /my-data-stream/_bulk?refresh=true
{"create":{"_id":null}}
{"name":"foo","value":"bar"}
{"create":{"_id":null}}
{"name":"foo2","value":"bar2"}
{"create":{"_id":null}}
{"name":"foo3","value":"bar3"}

```

If you have _many_ documents to index to a data stream, I'd recommend using the [bulk observable](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/indexing-documents.html#bulkall-observable) to do so

```auto
// 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
	.Index("my-data-stream")
	.RefreshOnCompleted()
	.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);
		waitHandle.Set();
	},
	onCompleted: () => waitHandle.Set());

bulkAllObservable.Subscribe(observer);
waitHandle.WaitOne();
exceptionDispatchInfo?.Throw();

```

---

<div class="post-metadata">

**Author:** ![buaaytt](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@buaaytt](https://discuss.elastic.co/u/buaaytt)\
**Post date:** [November 17, 2021, 10:20am UTC](https://discuss.elastic.co/t/can-nest-index-multiple-documents-to-a-data-stream/288949/3 "2021-11-17T10:20:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 15, 2021, 10:20am UTC](https://discuss.elastic.co/t/can-nest-index-multiple-documents-to-a-data-stream/288949/4 "2021-12-15T10:20:49Z")

</div>

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