首页 > 解决方案 > Elasticsearch:“脚本意外结束。”

问题描述

我在弹性搜索中有以下文档

{
  "_index" : "artgroup",
  "_type" : "_doc",
  "_id" : "199162315",
  "_version" : 2,
  "_seq_no" : 113,
  "_primary_term" : 4,
  "found" : true,
  "_source" : {
    "uuid" : "199162315",
    "GroupTitle" : "some GroupTitle",
    "GroupDetails" : "its an Updated artwork",
    "isNew" : true,
    "UserList" : [
      "1",
      "2",
      "3",
      "4"
    ]
  }
}

我正在尝试更新该字段GroupTitle这是我正在尝试做的事情

val updateRequest = new UpdateRequest(ARTGROUP_INDEX_NAME, artGroupUuid)
val fieldName = new Script(ScriptType.INLINE, "painless", "ctx._source.GroupTitle=", singletonMap("GroupTitle", "some updated groupTittle"))
updateRequest.script(fieldName)
val updateResponse = client.update(updateRequest, RequestOptions.DEFAULT);

但我收到以下异常

Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://localhost:9200], URI [/artgroup/_update/199162315?timeout=1m], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[sara-Inspiron-7773][192.168.1.2:9300][indices:data/write/update[s]]"}],"type":"illegal_argument_exception","reason":"failed to execute script","caused_by":{"type":"script_exception","reason":"compile error","script_stack":["ctx._source.GroupTitle=","                       ^---- HERE"],"script":"ctx._source.GroupTitle=","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"unexpected end of script.","caused_by":{"type":"no_viable_alt_exception","reason":null}}}},"status":400}
        at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:260)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:238)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212)
        at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433)
        ... 17 common frames omitted

我在“使用脚本更新”标题下关注此链接https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update.html什么我在这里失踪了吗?

标签: javaelasticsearch

解决方案


这是我解决这个问题的方法

val fieldName = new Script(ScriptType.INLINE, "painless", "ctx._source.GroupTitle=params.GroupTitle", singletonMap("GroupTitle", "blah"))

推荐阅读