Reputation: 5123
I'm trying to insert some JSON data into elastic search for testing.
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}
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.
The above error messsage is from NEST. Elastic replies (and write in the log) the following message: MapperParsingException[failed to parse]; nested- NotXContentException[Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes];
Failed to parse { ""hello"" : ""world"" } ????
Upvotes: 3
Views: 10383
Reputation: 125498
A few observations:
client.LowLevel
if you want to, but using an anonymous type is probably easier)..DebugInformation
on the response should have all of the details for why the request failedHere'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"
}
}
Upvotes: 11