I am trying to write code in C# for PUT and GET to my elasticsearch data. I typed code for PUT like this, and it seems that it works:
string url = "http://localhost:9200/my_index/my_type/";
JsonDocFormat json = new JsonDocFormat()
{
name = "John"
};
string s = JsonConvert.SerializeObject(json);
using (var client = new WebClient())
{
client.UploadString(url, "POST", s);
}
But I can't write code for this GET:
GET my_index/my_type/_search
{
"query" : {
"match" : {
"name" : "john"
}
}
}
I tried something like this:
string url_req = "http://localhost:9200/my_index/my_type/_search?pretty";
string s1 = "{\"query\": {\"match\": { \"name\" : \"john\" }}}";
string s_req = url_req + s1;
using (var client = new WebClient())
{
Console.Write(client.DownloadString(s_req));
}
But this code returned same output as for this GET:
GET /my_index/my_type/_search
It did not throw any error, but it absolutely ignored json body at the end of URL. I want to write this without any external package (as NEST or Elasticsearch.NET), just with HTTP.
Thanks in advance for any help!