【问题标题】:ElasticSearch Index Name is nullElasticSearch 索引名称为空
【发布时间】: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


    【解决方案1】:

    您将configuration["elasticsearch:index"] 设置为connection setting 中的默认索引,但您正在创建索引machine,错误背后的原因是configuration["elasticsearch:index"] 的索引值不是Elasticsearch 中的现有索引。

    【讨论】:

    • 其实有。我也在其中添加了一些值。但是 nvm,安装了 docker,今天要修复它。谢谢你的回答,顺便说一句。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 2015-01-19
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    相关资源
    最近更新 更多