question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BulkAll requires DefaultIndex or DefaultMappingFor with index

See original GitHub issue

From: https://discuss.elastic.co/t/nest-client-bulkall-requires-defaultindexfor-or-defaultindex-to-work/189766

The BulkAll method of ElasticClient requires

  • DefaultMappingFor<T>() with Index

or

  • DefaultIndex()

or

  • .Index() on the BulkAll call

to work.

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()

Repro

static void Main(string[] args)
{
	var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200"))
	.DisableDirectStreaming()
	.PrettyJson()
	.OnRequestCompleted(callDetails =>
	{
		if (callDetails.RequestBodyInBytes != null)
		{
			Console.WriteLine(
				$"{callDetails.HttpMethod} {callDetails.Uri} \n" +
				$"{Encoding.UTF8.GetString(callDetails.RequestBodyInBytes)}");
		}
		else
		{
			Console.WriteLine($"{callDetails.HttpMethod} {callDetails.Uri}");
		}

		Console.WriteLine();

		if (callDetails.ResponseBodyInBytes != null)
		{
			Console.WriteLine($"Status: {callDetails.HttpStatusCode}\n" +
					 $"{Encoding.UTF8.GetString(callDetails.ResponseBodyInBytes)}\n" +
					 $"{new string('-', 30)}\n");
		}
		else
		{
			Console.WriteLine($"Status: {callDetails.HttpStatusCode}\n" +
					 $"{new string('-', 30)}\n");
		}
	});
	//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; }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
russcamcommented, Aug 12, 2019

I’ve added https://github.com/elastic/elasticsearch-net/pull/4017 to include additonal details in the XML docs

0reactions
russcamcommented, Aug 12, 2019

I’m ++ in keeping as is. and improving the documentation. I’ll add something now

Read more comments on GitHub >

github_iconTop Results From Across the Web

NEST Client `BulkAll` requires `DefaultIndexFor` or ...
Map an index name using ConnectionSettings.DefaultMappingFor<TDocument>() or set a default index using ConnectionSettings.DefaultIndex().
Read more >
How to specify the index name using attribute using NEST ...
When using BulkAll , you can specify an index name per bulk operation using BufferToBulk(...) private static void Main() { var defaultIndex =...
Read more >
Getting Started With Elastic Using .Net NEST Library, Part ...
In Elastic, you index, search, sort and filter documents—not rows of columnar ... and will be indexed as it is; No - value...
Read more >
Interface IBulkAllRequest<T> | OpenSearch.Net
The index to use for items that don't specify one. By default, will be inferred from T . If no default index has...
Read more >
More advanced features of the high-level .NET client
Indexing documents individually is inefficient because it creates an HTTP request for every document sent. The BulkAll helper frees you from handling retry, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found