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; }
}
}