无法使用NEST将动态对象插入弹性搜索 [英] Unable to insert dynamic object to Elastic Search using NEST
问题描述
这是我试过的。
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();
字典< 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表的行和列。
我会错了。
问候,
Hema
p>我相信你可以跳过 ExpandoObject
,只是索引 Dictionary< string,object>()
。
var dictionary = new Dictionary< string,object>();
dictionary.Add(NewProp,test1);
dictionary.Add(NewProp3,test1);
client.Index(dictionary);
I am creating a dynamic object. I assign the values via IDictionary. Add the collections of the IDictionary to the object. Then I add the dynamic object to Elastic Search using NEST code. It throws me stackoverflow exception."An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll"
Here is what I have tried.
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;
}
I need to create an index in ElasticSearch, using a dynamic object, because I will be having an excel work book consisting of over 300 worksheet, and each and every sheet will be named as type, and the contents inside the worksheet will be the _source.
In the above example 'x' the dynamic object created is the name of the worksheet, and the values added into the dictionary are the rows and columns of excel sheet.
Where am I going wrong.
Regards, Hema
I belive you can skip ExpandoObject
and just index Dictionary<string, object>()
.
var dictionary = new Dictionary<string, object>();
dictionary.Add("NewProp", "test1");
dictionary.Add("NewProp3", "test1");
client.Index(dictionary);
这篇关于无法使用NEST将动态对象插入弹性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!