I have some json file need to import to elasticsearch.
I use the curl api. The below is sample and it work fine for me.
curl -XPOST http://localhost:9200/index_local/_doc/_bulk -H "Content-Type: application/json" --data-binary @sample.json
I use the HttpWebRequest to simulate and it work fine for me too.
public void Post(string fileName)
{
try
{
// get the byte array
var data = File.ReadAllBytes(fileName);
// create HttpRequest
var httpRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:9200/index_local/_doc/_bulk");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/json";
httpRequest.ContentLength = data.Length;
// set the file byte array to the stream
using (var requestStream = httpRequest.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
}
// get the response
using (var response = httpRequest.GetResponse() as HttpWebResponse)
{
using (var responseStream = new StreamReader(response.GetResponseStream()))
{
// read the result
Console.WriteLine(responseStream.ReadToEnd());
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
But I can't find the bulk api with import json file with elasticsearch.net.
Is there have some function equal to HttpWebRequest that can post the json file to elasticsearch ?
Is elasticsearch.net library ElasticLowLevelClient or ElasticClient support to import json file with btye array ?