Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk update via elastic search Java API throws exception

Bulk update in elastic search Java Api throws the following exception.

org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: no requests added;
at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:29)
at org.elasticsearch.action.bulk.BulkRequest.validate(BulkRequest.java:412)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:55)
at org.elasticsearch.action.bulk.TransportBulkAction$TransportHandler.messageReceived(TransportBulkAction.java:299)
at org.elasticsearch.action.bulk.TransportBulkAction$TransportHandler.messageReceived(TransportBulkAction.java:288)
at org.elasticsearch.transport.netty.MessageChannelHandler.handleRequest(MessageChannelHandler.java:207)
at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:108)
at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:109)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:90)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

Below is the code I have written.

    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();

    for (String documentId : documentIds)
    {
        bulkRequestBuilder.add(client.prepareUpdate("39302", "3", documentId).setScript("ctx._source.customerName=\"Ramaraj\";"));
    }

    BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();

This the same way I have written for bulk index also. It was working fine.

Thanks in advance.

Note:Bulk Update in java api is added only few days back.

like image 590
Ramaraj Karuppusamy Avatar asked Jun 27 '13 13:06

Ramaraj Karuppusamy


3 Answers

As the exception says, no requests were added to the BulkRequest object. Debug if the records you add in the for loop are actually being added to the builder object. Found this post recently with the same issue: ActionRequestValidationException

like image 128
Goku Avatar answered Oct 12 '22 13:10

Goku


This exception happens because your documentIds collection is empty.

You should to check if your collection (list, queue, etc) does have documents before make the request. I come across the same problem yesterday, in my case the elastic search insertions happen in a given interval (lets say 5s), not very ofter the insertion collection was empty;

In my case this is a very rare occurrence, and would only happen rarely (in my case 3 million documents inserted every day), and might be difficult to identify before go to production.

I would handle your exception like this:

if(!documentIds.isEmpty())
{   
     BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();

    for (String documentId : documentIds)
    {
        bulkRequestBuilder.add(client.prepareUpdate("39302", "3", documentId).setScript("ctx._source.customerName=\"Ramaraj\";"));
    }

    BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
}
like image 20
SQL.injection Avatar answered Oct 12 '22 13:10

SQL.injection


The error is because of size of your BulkRequestBuilder, which has no requests. Debug if your builder contains any Requests

enter image description here

like image 21
prayagupa Avatar answered Oct 12 '22 11:10

prayagupa