I am executing using bulk api. then some error
elasticsearch version : 5.1.2
org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: no requests added;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.net.InetAddress;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class EsBulk {
public EsBulk() {
System.out.println("inside Java ");
insertES();
System.out.println("Execute From scala ES ");
}
void insertES() {
try {
Settings settings = Settings.builder()
.put("cluster.name","elasticsearch")
.put("client.transport.ignore_cluster_name",true)
.put("client.transport.ping_timeout","20s")
.build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
BulkRequestBuilder bulkRequest = client.prepareBulk();
bulkRequest.get();
// either use client#prepare, or use Requests# to directly build index/delete
// requests
bulkRequest.add(client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder().startObject().field("user", "kimchy").field("postDate", 100)
.field("message", "trying out Elasticsearch").endObject()));
bulkRequest.add(client.prepareIndex("twitter", "tweet", "2").setSource(jsonBuilder().startObject()
.field("user", "kimchy").field("postDate", 200).field("message", "another post").endObject()));
System.out.println("ElasticSearch tesing");
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
// process failures by iterating through each bulk response item
System.out.println("fail");
}
} catch (Exception e) {
System.err.println(e);
}
}
void testConnect() {
System.out.println("Java Program !!! ");
}
}
my elasticsearch.yml
network.bind_host: 0.0.0.0
network.publish_host: 127.0.0.1
# Set a custom port for HTTP:
#
# http.port: 9200
#
transport.tcp.port: 9300
transport.tcp.compress: true
transport.host: 0.0.0.0
bootstrap.seccomp: false
script.engine.groovy.inline.search: on
script.engine.groovy.inline.aggs: on
http.cors.enabled: true
http.cors.allow-origin: "*"
what shoud i do ?? plz help