getting org.elasticsearch.action.ActionRequestValidationException?

Hi

I am using elastic server 0.16.2.i have used following code for
RabbitMQRiver:

public class RabbitMQRiverTest {

public static void main(String[] args) throws Exception {

    Node node =

NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type",
"none")).node();

    node.client().prepareIndex("_river", "test1",

"_meta").setSource(jsonBuilder().startObject().field("type",
"rabbitmq").endObject()).execute().actionGet();

    ConnectionFactory cfconn = new ConnectionFactory();
    cfconn.setHost("localhost");
    cfconn.setPort(AMQP.PROTOCOL.PORT);
    Connection conn = cfconn.newConnection();

    Channel ch = conn.createChannel();
    ch.exchangeDeclare("elasticsearch", "direct", true);
    ch.queueDeclare("elasticsearch", true, false, false, null);

    String message = "{ \"index\" : { \"index\" : \"test\", \"type

" : "type1", "id" : "1"} }\n" +
"{ "type1" : { "field1" : "value1" } }\n" +
"{ "delete" : { "index" : "test", "type" :
"type1", "id" : "2" } }\n" +
"{ "create" : { "index" : "test", "type" :
"type1", "id" : "1" }}\n" +
"{ "type1" : { "field1" : "value1" } }";
System.out.println(message);
ch.basicPublish("elasticsearch", "elasticsearch", null,
message.getBytes());
System.out.println("publish sucessfully");
ch.close();
conn.close();

}

}

I got the following exception:

org.elasticsearch.action.ActionRequestValidationException: Validation
Failed: 1: index is missing2: type is missing3: index is missing4:
type is missing5: id is missing6: index is missing7: type is missing8:
index is missing9: type is missing10: index is missing11: type is
missing12: id is missing
at
org.elasticsearch.action.bulk.BulkRequest.validate(BulkRequest.java:
239)
at
org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:
55)
at org.elasticsearch.client.node.NodeClient.bulk(NodeClient.java:136)
at
org.elasticsearch.client.action.bulk.BulkRequestBuilder.doExecute(BulkRequestBuilder.java:
122)
at
org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
56)
at org.elasticsearch.river.rabbitmq.RabbitmqRiver
$Consumer.run(RabbitmqRiver.java:277)
at java.lang.Thread.run(Thread.java:619)

please tell me where is the problem and solution for this exception.

Thanks

Format of your String message is incorrect.
Don't forget the underscores _ for _type, _id, _index

See here : Elasticsearch Platform — Find real-time answers at scale | Elastic

HTH
David :wink:
@dadoonet

Le 30 nov. 2011 à 06:08, sam mishra.sameek@gmail.com a écrit :

Hi

I am using elastic server 0.16.2.i have used following code for
RabbitMQRiver:

public class RabbitMQRiverTest {

public static void main(String args) throws Exception {

   Node node =

NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type",
"none")).node();

   node.client().prepareIndex("_river", "test1",

"_meta").setSource(jsonBuilder().startObject().field("type",
"rabbitmq").endObject()).execute().actionGet();

   ConnectionFactory cfconn = new ConnectionFactory();
   cfconn.setHost("localhost");
   cfconn.setPort(AMQP.PROTOCOL.PORT);
   Connection conn = cfconn.newConnection();

   Channel ch = conn.createChannel();
   ch.exchangeDeclare("elasticsearch", "direct", true);
   ch.queueDeclare("elasticsearch", true, false, false, null);

   String message = "{ \"index\" : { \"index\" : \"test\", \"type

" : "type1", "id" : "1"} }\n" +
"{ "type1" : { "field1" : "value1" } }\n" +
"{ "delete" : { "index" : "test", "type" :
"type1", "id" : "2" } }\n" +
"{ "create" : { "index" : "test", "type" :
"type1", "id" : "1" }}\n" +
"{ "type1" : { "field1" : "value1" } }";
System.out.println(message);
ch.basicPublish("elasticsearch", "elasticsearch", null,
message.getBytes());
System.out.println("publish sucessfully");
ch.close();
conn.close();

}
}

I got the following exception:

org.elasticsearch.action.ActionRequestValidationException: Validation
Failed: 1: index is missing2: type is missing3: index is missing4:
type is missing5: id is missing6: index is missing7: type is missing8:
index is missing9: type is missing10: index is missing11: type is
missing12: id is missing
at
org.elasticsearch.action.bulk.BulkRequest.validate(BulkRequest.java:
239)
at
org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:
55)
at org.elasticsearch.client.node.NodeClient.bulk(NodeClient.java:136)
at
org.elasticsearch.client.action.bulk.BulkRequestBuilder.doExecute(BulkRequestBuilder.java:
122)
at
org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
56)
at org.elasticsearch.river.rabbitmq.RabbitmqRiver
$Consumer.run(RabbitmqRiver.java:277)
at java.lang.Thread.run(Thread.java:619)

please tell me where is the problem and solution for this exception.

Thanks