Gio*_*iox 3 c# json elasticsearch nest kibana
我正在尝试将一些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()
);
Run Code Online (Sandbox Code Playgroud)
没有插入任何内容,我从ES收到以下错误:{在PUT上对无效的低级别调用构建的无效NEST响应:/ FormId/resp/1?refresh = true}
我试图找到一些例子,但都使用预定义的数据结构,而我想使用非结构化数据的JSON数据.
以上错误消息来自NEST.弹性回复(并在日志中写入)以下消息:MapperParsingException [无法解析]; nested- NotXContentException [压缩器检测只能在某些xcontent字节或压缩的xcontent字节上调用];
无法解析{""你好"":""世界""} ????
Rus*_*Cam 10
一些观察:
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()
);
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我们发出GET请求,http://localhost:9200/formid/resp/1我们就会收回文档
{
"_index": "formid",
"_type": "resp",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"hello": "world"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8476 次 |
| 最近记录: |