I want to send data to ElasticSearch using java httprequest
calling _bulk
api of the elasticsearch.
Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
This gives me this error
"Response: HttpResponseProxy{HTTP/1.1 406 Not Acceptable [content-type: application/json; charset=UTF-8] org.apache.http.client.entity.DecompressingEntity@3532ec19}"
Below is my Java Code:
package com.ElasticPublisher;
import java.io.File;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.FileEntity;
import org.apache.http.impl.client.HttpClientBuilder;
public class ElasticPublisher {
public static void main(String args[]){
try {
sendFile();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void sendFile() throws Exception{
String fileName = "C:\\Users\\malin\\Documents\\ELK\\employee.json";
File jsonFile = new File(fileName);
HttpEntity entity = new FileEntity(jsonFile);
HttpPost post = new HttpPost("http://localhost:9200/_bulk");
post.setEntity(entity);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
HttpClient client = clientBuilder.build();
post.addHeader("content-type", "text/plain");
post.addHeader("Accept","text/plain");
HttpResponse response = client.execute(post);
System.out.println("Response: " + response);
}
}
*