无法使用NEST将动态对象插入弹性搜索 [英] Unable to insert dynamic object to Elastic Search using NEST

查看:152
本文介绍了无法使用NEST将动态对象插入弹性搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个动态对象。我通过IDictionary分配值。将IDictionary的集合添加到对象。然后我使用NEST代码将动态对象添加到弹性搜索。它抛出了我的stackoverflow异常。一个未处理的异常类型System.StackOverflowException发生在mscorlib.dll



这是我试过的。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆