visual-studio - ElasticSearch 索引名称为空
问题描述
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.
解决方案
您正在设置configuration["elasticsearch:index"]
为您的默认索引,connection setting
但您正在创建 index machine
,错误背后的原因是 index 的值configuration["elasticsearch:index"]
不是 Elasticsearch 中的现有索引。
推荐阅读
- javascript - 我该如何处理错误,忽略它并继续使用该功能?不和谐.js
- sql - SQL - 在两列中对字符进行分组和计数
- c - 使用两个管道在父进程和子进程之间进行通信
- ios - SwiftUI 背景默认为渐变
- c# - .csproj 中指定的 NuGet 包的版本号与包的版本号不匹配
- java - 从黄瓜 4.2.3 升级到 5.1.3 后 Cucumber runner 类初始化错误
- r - 有没有办法使用闪亮的下载按钮从应用程序下载(非导入/操作)数据?
- python-3.x - Model.fit 值误差(文本分类模型)
- python - 在 Tensorflow 2.x 中我们不需要指定输入形状吗?
- wordpress - 如何编写 .htaccess 以将 url 重定向到 AWS CloudFront?