# NEST Client \`BulkAll\` requires \`DefaultIndexFor\` or \`DefaultIndex\` to work

**URL:** https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766
**Category:** Elasticsearch
**Created:** [July 10, 2019, 12:34pm UTC](https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766 "2019-07-10T12:34:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![blemasle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blemasle/32/49761_2.png) [@blemasle](https://discuss.elastic.co/u/blemasle)
#### Post date: [July 10, 2019, 12:34pm UTC](https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766/1 "2019-07-10T12:34:54Z")

</div>

Hello there,

Don't know if it's a bug or a requirement, but the NEST client `BulkAll` method of `ElasticClient` requires you to call `DefaultIndexFor<T>()` or `DefaultIndex()` before hand. You'll get an `ArgumentException` otherwise : `Index name is null for the given type and no default index is set. Map an index name using ConnectionSettings.DefaultMappingFor<TDocument>() or set a default index using ConnectionSettings.DefaultIndex()`

Even if you specify all `Index` in all operations using `BufferToBulk`. Who cares of a default index if all operations provide an index name ? 🤔 Why would I ever have to choose an index name that will _never_ be used ?

Could someone enlighten me on either the correct path to take with `BulkAll` or if this is actually a bug ?

Bertrand

netcore app 2.1  
NEST 7.0.1

```
class Program
{
	static void Main(string[] args)
	{
		var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200"));
		//uncomment one of the following lines to crash
		//connectionSettings.DefaultMappingFor<Document>(d => d.IndexName("myindex"));
		//connectionSettings.DefaultIndex("mydefaultindex");

		ElasticClient client = new ElasticClient(connectionSettings);

		BulkAllObservable<Document> bulk = client.BulkAll(GetDocuments(), b => b
			.BufferToBulk((descriptor, list) =>
			{
				foreach (Document doc in list)
				{
					descriptor.Index<Document>(bi => bi
						.Index($"myindex-{doc.Date:yyyy.mm.dd}")
						.Document(doc)
					);
				}
			})
			.Size(2)
		);

		bulk.Subscribe(new BulkAllObserver(
			onNext: r => Console.WriteLine(string.Join(";", r.Items.Select(i => i.Id))),
			onError: e => Console.Error.WriteLine(e),
			onCompleted: () => Console.WriteLine("Done")
		));
		bulk.Wait(TimeSpan.FromSeconds(30), null);
	}

	private static IEnumerable<Document> GetDocuments()
	{
		for(int i = 0; i < 10; i++)
		{
			yield return new Document { Date = DateTime.UtcNow.AddDays(i) };
		}
	}

	private class Document
	{
		public DateTime Date { get; set; }
	}
}
```

---

<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: [July 15, 2019, 5:33am UTC](https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766/2 "2019-07-15T05:33:16Z")

</div>

Thanks for raising this question, @blemasle. This indeed looks like a bug , so I've opened [https://github.com/elastic/elasticsearch-net/issues/3951](https://github.com/elastic/elasticsearch-net/issues/3951)

---

<div class="post-metadata">

### Author: ![blemasle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blemasle/32/49761_2.png) [@blemasle](https://discuss.elastic.co/u/blemasle)
#### Post date: [July 17, 2019, 7:18am UTC](https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766/3 "2019-07-17T07:18:27Z")

</div>

Thanks @forloop 🙂 I'll look into it

---

<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: [August 14, 2019, 7:18am UTC](https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766/4 "2019-08-14T07:18:31Z")

</div>

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