【发布时间】:2026-02-09 11:30:02
【问题描述】:
我正在创建一个动态对象。我通过 IDictionary 分配值。将 IDictionary 的集合添加到对象。然后我使用 NEST 代码将动态对象添加到 Elastic Search。它向我抛出了 * 异常。“在 mscorlib.dll 中发生了 'System.*Exception' 类型的未处理异常”
这是我尝试过的。
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node,defaultIndex: "test-index");
var client = new ElasticClient(settings);
try
{
dynamic x = new ExpandoObject();
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("NewProp", "test1");
dic.Add("NewProp3", "test1");
x = dic;
var index3 = client.Index(x);
}
catch (Exception ex)
{
string j = ex.StackTrace;
}
我需要使用动态对象在 ElasticSearch 中创建一个索引,因为我将拥有一个包含 300 多个工作表的 excel 工作簿,并且每个工作表都将被命名为类型,工作表中的内容将成为_source。
在上面的例子中,'x'创建的动态对象是工作表的名称,添加到字典中的值是excel表的行和列。
我哪里错了。
问候, 盒马
【问题讨论】:
标签: elasticsearch nest