Java Rest Client

Hi guys,

I have been trying unsuccessfully to do a bulk insert with the new Java rest client... Does anyone have a working example of a bulk insert using the rest client ?
I can do searches and index single documents without any issue but no bulk operations. I have tried with pretty much all the types of http entities but I am always getting a 400.
Here is a small example:
StringBuilder batch = new StringBuilder();
String bulkline = "{"index": {}}\n";
batch.append(bulkline);
batch.append("{"kukta": "haha"}");
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();
HttpEntity entity = new NStringEntity(batch.toString(), ContentType.APPLICATION_JSON);
Response indexResponse = restClient.performRequest(
"POST",
"/kukta/test/_bulk",
Collections.<String, String>emptyMap(),
entity);

Thanks a lot,
Simeon

May be this code can help you. Look at bulk method.

https://github.com/dadoonet/fscrawler/blob/master/src/main/java/fr/pilato/elasticsearch/crawler/fs/client/ElasticsearchClient.java

Thanks a lot!
I was missing a trailing newline in my bulk request

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.