Hello people,
I am trying to bulk update in elasticSearch using java.
I have a JSON list and I'm passing that list in bulk request to update, but its throwing an error as below :
Exception in thread "main" java.lang.IllegalArgumentException: The number of object passed must be even but was [1]
at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:474)
at com.elastic.search.BulkUpdateApi.main(BulkUpdateApi.java:48)
My java code is :
RestHighLevelClient highLevelRestClient = new RestHighLevelClient(builder);
BulkRequest bulkRequest = new BulkRequest();
File file = new File("D:\\local\\list.JSON");
bulkRequest.add(new IndexRequest().source(XContentType.JSON, file));
try {
BulkResponse bulkResponse = highLevelRestClient.bulk(bulkRequest, RequestOptions.DEFAULT);
String a = "dummy";
System.out.println(bulkResponse.toString());
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
highLevelRestClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
My JSON File is :
{ "update" : {"_id" : "1", "_index" : "dummy", "retry_on_conflict" : 3} }
{ "doc" : {"price" : "420"} }
{ "update" : { "_id" : "2", "_index" : "dummy", "retry_on_conflict" : 3} }
{ "doc" : {"price" : "520"}, "doc_as_upsert" : true }
{ "update" : {"_id" : "3", "_index" : "dummy", "_source" : true} }
{ "doc" : {"price" : "120"} }
{ "update" : {"_id" : "4", "_index" : "dummy"} }
{ "doc" : {"price" : "320"}, "_source": true}