BulkAll requires DefaultIndex or DefaultMappingFor with index
See original GitHub issueThe 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:
- Created 4 years ago
- Reactions:1
- Comments:10 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve added https://github.com/elastic/elasticsearch-net/pull/4017 to include additonal details in the XML docs
I’m ++ in keeping as is. and improving the documentation. I’ll add something now