Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot execute query with script #2894

Open
Amitlevizky3 opened this issue Jul 26, 2023 · 0 comments
Open

Cannot execute query with script #2894

Amitlevizky3 opened this issue Jul 26, 2023 · 0 comments

Comments

@Amitlevizky3
Copy link

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"))
    )
}

Do you happen to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant