Unable to insert dynamic object in Elastic Search using NEST

I am creating a dynamic object. I am assigning values ​​through an IDictionary. Add collections of the IDictionary to the object. Then I add the dynamic object to Elastic Search using the NEST code. This throws a 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 have an Excel workbook consisting of more than 300 sheets, and each sheet will be named as a type, and the contents inside the sheet will be the source.

In the above "x" example, the created dynamic object is the name of the worksheet, and the values ​​added to the dictionary are the rows and columns of the excel sheet.

Where am I mistaken.

Regards, Hema

0
source share
1 answer

I believe 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); 
+1
source

Source: https://habr.com/ru/post/986957/


All Articles