【发布时间】:2021-09-17 09:22:45
【问题描述】:
System.ArgumentException:
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().
错误信息在上面!
var url = configuration["elasticsearch:url"];
var defaultIndex = configuration["elasticsearch:index"];
var settings = new ConnectionSettings(new Uri(url)).DefaultMappingFor<MachineConnectionInformation>(x=> x.IndexName(defaultIndex));
var client = new ElasticClient(settings);
client.Indices.Create("machine", index => index.Map<MachineConnectionInformation>(x => x.AutoMap()));
services.AddSingleton(client);
上面是我的扩展代码!
var response = _client.IndexDocument(model); //this is where i add my model to elastic.
【问题讨论】:
标签: visual-studio asp.net-core elasticsearch postman kibana