我正在尝试将一些JSON数据插入弹性搜索以进行测试。
这是代码:
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node);
settings.DefaultIndex("FormId");
var client = new ElasticClient(settings);
var myJson = @"{ ""hello"" : ""world"" }";
var response = client.Index(myJson, i => i.Index("FormId")
.Type("resp")
.Id((int)r.id)
.Refresh()
);
没有插入任何内容,并且从ES中收到以下错误:{无效的NEST响应是由对PUT的不成功的低级调用生成的:/ FormId / resp / 1?refresh = true}
我试图找到一些示例,但是所有示例都使用预定义的数据结构,而我想使用JSON数据和非结构化数据。
上面的错误消息来自NEST。弹性回复(并写入日志)以下消息:MapperParsingException [无法解析];nested-NotXContentException [压缩器检测只能在某些xcontent字节或压缩的xcontent字节上调用];
无法解析{“” hello“”:“” world“”} ????
一些观察:
client.LowLevel
如果你想,但使用匿名类型是可能更容易)。.DebugInformation
对响应应该具有的所有细节请求失败的原因这是一个演示如何开始的示例
void Main()
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node)
// lower case index name
.DefaultIndex("formid");
var client = new ElasticClient(settings);
// use an anonymous type
var myJson = new { hello = "world" };
// create the index if it doesn't exist
if (!client.IndexExists("formid").Exists)
{
client.CreateIndex("formid");
}
var indexResponse = client.Index(myJson, i => i
.Index("formid")
.Type("resp")
.Id(1)
.Refresh()
);
}
现在,如果我们发出GET请求,http://localhost:9200/formid/resp/1
我们将取回文档
{
"_index": "formid",
"_type": "resp",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"hello": "world"
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句