ElasticSearch Index/Insert with NEST fail ElasticSearch Index/Insert with NEST fail json json

ElasticSearch Index/Insert with NEST fail


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 i.e. client.LowLevel if you want to, but using an anonymous type is probably easier).
  • The .DebugInformation on the response should have all of the details for why the request failed

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

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