简体   繁体   English

EEST的ElasticSearch索引/插入失败

[英]ElasticSearch Index/Insert with NEST fail

I'm trying to insert some JSON data into elastic search for testing. 我正在尝试将一些JSON数据插入到弹性搜索中进行测试。

here is the code: 这是代码:

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

Nothing is inserted, and I get the following error from ES: {Invalid NEST response built from a unsuccesful low level call on PUT: /FormId/resp/1?refresh=true} 没有插入任何内容,我从ES收到以下错误:{在PUT上对无效的低级别调用构建的无效NEST响应:/ FormId / resp / 1?refresh = true}

I've tried to find some example on that but all use a predefined structure of data, instead I want to use JSON data, with unstructured data. 我试图找到一些例子,但都使用预定义的数据结构,而我想使用非结构化数据的JSON数据。

The above error messsage is from NEST. 以上错误消息来自NEST。 Elastic replies (and write in the log) the following message: MapperParsingException[failed to parse]; 弹性回复(并在日志中写入)以下消息:MapperParsingException [无法解析]; nested- NotXContentException[Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes]; nested- NotXContentException [压缩器检测只能在某些xcontent字节或压缩的xcontent字节上调用];

Failed to parse { ""hello"" : ""world"" } ???? 无法解析{“”你好“”:“”世界“”} ????

A few observations: 一些观察:

  • the index name needs to be lowercase 索引名称必须小写
  • the index will be automatically created when you index a document into it, although this feature can be turned off in configuration. 虽然可以在配置中关闭此功能,但在将文档编入索引时将自动创建索引。 If you'd like to also control the mapping for the document, it's best to create the index first. 如果您还想控制文档的映射,最好先创建索引。
  • use an anonymous type to represent the json you wish to send (you can send a json string with the low level client ie client.LowLevel if you want to, but using an anonymous type is probably easier). 使用匿名类型来表示您希望发送的json(您可以使用低级客户端发送json字符串,即client.LowLevel如果您愿意,但使用匿名类型可能更容易)。
  • The .DebugInformation on the response should have all of the details for why the request failed 响应中的.DebugInformation应该包含请求失败原因的所有详细信息

Here's an example to demonstrate how to get started 这是一个演示如何入门的示例

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

Now if we make a GET request to http://localhost:9200/formid/resp/1 we get back the document 现在,如果我们向http://localhost:9200/formid/resp/1发出GET请求,我们将返回文档

{
   "_index": "formid",
   "_type": "resp",
   "_id": "1",
   "_version": 1,
   "found": true,
   "_source": {
      "hello": "world"
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM