Class cast exception while updating documents

While updating all documents in an index using _update_by_query I get the following error:

{
"error": {
"root_cause": [
{
"type": "class_cast_exception",
"reason": "java.lang.String incompatible with java.util.Map"
}
],
"type": "class_cast_exception",
"reason": "java.lang.String incompatible with java.util.Map"
},
"status": 500
}

Query executed was:

POST raw_requests_bib/_update_by_query
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "user": "ba1"
              }
            }
          ]
        }
      }
    }
  },
  "script" : "ctx._source.user = BA1;"
}

My documents look like this:

{
"time": "12-12-2018--09-12-38",
"user": "ba1",
"url": "/page1"
}

Executed this on kibana devtools page.
I do not have access to elasticsearch logs for this. Any leads would be helpful.

Without logs it will be difficult to investigate. We need the full stacktrace (which is printed in the log).

However, at a glance, what is BA1? If you mean this to be a string literal, it needs to be in quotes:

"script" : "ctx._source.user = 'BA1';"

Sorry for the late reply. I was able to get the logs from the server.

[2018-12-26T15:23:39,068][WARN ][r.suppressed ] path: /raw_requests_bib/_update_by_query, params: {index=raw_requests_bib}
java.lang.ClassCastException: java.lang.String incompatible with java.util.Map
at org.elasticsearch.index.reindex.RestUpdateByQueryAction.lambda$buildRequest$1(RestUpdateByQueryAction.java:65) ~[?:?]
at org.elasticsearch.index.reindex.RestUpdateByQueryAction$$Lambda$2051.000000002FC44C90.accept(Unknown Source) ~[?:?]
at org.elasticsearch.index.reindex.AbstractBulkByQueryRestHandler.extractRequestSpecificFields(AbstractBulkByQueryRestHandler.java:94) ~[?:?]
at org.elasticsearch.index.reindex.AbstractBulkByQueryRestHandler.parseInternalRequest(AbstractBulkByQueryRestHandler.java:57) ~[?:?]
at org.elasticsearch.index.reindex.RestUpdateByQueryAction.buildRequest(RestUpdateByQueryAction.java:67) ~[?:?]
at org.elasticsearch.index.reindex.RestUpdateByQueryAction.buildRequest(RestUpdateByQueryAction.java:41) ~[?:?]
at org.elasticsearch.index.reindex.AbstractBaseReindexRestHandler.doPrepareRequest(AbstractBaseReindexRestHandler.java:54) ~[?:?]
at org.elasticsearch.index.reindex.RestUpdateByQueryAction.prepareRequest(RestUpdateByQueryAction.java:50) ~[?:?]
at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:64) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:262) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:200) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.http.netty4.Netty4HttpServerTransport.dispatchRequest(Netty4HttpServerTransport.java:505) [transport-netty4-5.6.7.jar:5.6.7]
at org.elasticsearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:80) [transport-netty4-5.6.7.jar:5.6.7]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at org.elasticsearch.http.netty4.pipelining.HttpPipeliningHandler.channelRead(HttpPipeliningHandler.java:68) [transport-netty4-5.6.7.jar:5.6.7]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [netty-codec-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [netty-codec-4.1.13.Final.jar:4.1.13.Final]
....
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:544) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:498) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) [netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-common-4.1.13.Final.jar:4.1.13.Final]
at java.lang.Thread.run(Thread.java:785) [?:1.8.0-internal]

Please let me know if this could be helped.

Also, tried "script" : "ctx._source.user = 'BA1';" but that did not help.

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