1

I have indexed a document PUT test/_doc/1

{
    "counter" : 1,
    "tags" : ["red"]
}

I am using script to update my content of the documents POST test/_doc/1/_update

{
    "script" : {
        "source": "ctx._source.tags.add(params.tag)",
        "lang": "painless",
        "params" : {
            "tag" : "blue"
        }
    }
}

POST test/_doc/1/_update

{
    "script" : "ctx._source.new_field = 'value_of_new_field'"
}

This two scripts are working fine individually, I want to use these two script statements in a single "_update" API. Is it possible to do this?

2
  • Yes, simply add a semicolon at the end of each statement Commented Oct 8, 2018 at 12:28
  • { "script" : { "source": "ctx._source.tags.add(params.tag)"; "ctx._source.new_field = 'value_of_new_field'", "lang": "painless", "params" : { "tag" : "blue" } } } Something like this? Commented Oct 8, 2018 at 14:28

1 Answer 1

2

You can simply add semicolons between statements, like this:

{
  "script": {
    "source": "ctx._source.tags.add(params.tag); ctx._source.new_field = 'value_of_new_field';",
    "lang": "painless",
    "params": {
      "tag": "blue"
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.