Unable to insert dynamic object to Elastic Search using NEST

我们两清 提交于 2019-12-12 00:35:45

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/33579086/unable-to-insert-dynamic-object-to-elastic-search-using-nest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!