sarah w
sarah w

Reputation: 3475

Elasticsearch: "unexpected end of script."

i have a following document in 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"
    ]
  }
}

i am trying to update the field GroupTitle here is how i am trying to do

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);

but i am getting the following exception

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

i am following this link https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update.html under the heading "Updates with the scripts" what i am missing here?

Upvotes: 0

Views: 587

Answers (1)

sarah w
sarah w

Reputation: 3475

here is how i solved this issue

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

Upvotes: 1

Related Questions