Reputation: 11
I'm trying to merge the payload from a consumer with an existing document in my Elasticsearch index using elastic4s 7.17.2. However, when I execute the query with the provided script, I'm getting an error from Elasticsearch:
[
{
"itemId" : 0,
"id" : "123456",
"index" : "myindex",
"type" : "_doc",
"version" : 0,
"forcedRefresh" : false,
"seqNo" : 0,
"primaryTerm" : 0,
"found" : false,
"created" : false,
"result" : null,
"status" : 400,
"error" : {
"type" : "illegal_argument_exception",
"reason" : "failed to execute script",
"index_uuid" : null,
"shard" : 0,
"index" : null,
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error"
}
},
"shards" : null,
"get" : null
}
]
Here is my code (Scala - compiled succesfully):
override val request: UpdateRequest = {
val retryCount = 5
val mergeScript =
"""
|def merge(s, t) {
| if (s == null) {
| return t
| }
| if (!(t instanceof Map)) {
| return s
| }
|
| for (entry in t.entrySet()) {
| s[entry.key] = merge(s[entry.key], entry.value)
| }
|
| return s
|}
|
|ctx._source = merge(ctx._source, params)
|""".stripMargin
updateById(index, id)
.retryOnConflict(retryCount)
.script(
Script(mergeScript).params(Map("param1" -> "100", "param2" -> "5"))
)
}
Does anyone know what could be the issue here?
I'm using elastic4s 7.17.2
I've tried to play a little bit with the syntax and to search in elastic4s repo but did not find any solution.
Upvotes: 1
Views: 39