Add Map to Array with Painless script


(Matthias Wilhelm) #1

Wanted to convert a script to painless which was quite painful. had the following problem:

this works:

POST /logstash-test/test/7/_update
{
    "scripted_upsert":true,
    "script" : {
        "lang": "painless",
        "inline": "ctx._source.messages=[]; ctx._source.messages.add('23')",
        "params" : {
            "event" : {"@timestamp":"11232"}
        }
    }
}

this doesn't work

POST /logstash-test/test/7/_update
{
    "scripted_upsert":true,
    "script" : {
        "lang": "painless",
        "inline": "ctx._source.messages=[]; ctx._source.messages.add(['test':'123'])",
        "params" : {
            "event" : {"@timestamp":"11232"}
        }
    }
}

i get the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse [messages]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse [messages]",
    "caused_by": {
      "type": "illegal_state_exception",
      "reason": "Can't get text on a START_OBJECT at 1:14"
    }
  },
  "status": 400
}

how can i make this work (Elasticsearch 5.1)? thx!


(system) #2

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