How to replace fields value

Hi

I'm trying to automate the creation of scripted fields. For updating the "fields" field, it has a string value. So, I cant update it with "source": "ctx._source.fields.add(params.field)" by adding to the array. So what is the best way to update the field?

Is there a way to simply replace the field value with something like source": "ctx._source.fields = params.field"?

You should be able to just update the entire Index Pattern document with a new document that contains your updates

I tried doing a partial update with the following:

curl -XPOST 'localhost:9200/.kibana/doc/index-pattern:5cd01980-e173-11e7-b90c-9930744e76ad/_update?pretty' -H 'Content-Type: application/json' -d'
{
"script" : "ctx._source.index\u002Dpattern.title = \u0027pddd\u0027"
}
'

but it returned the following:

{
"error" : {
"root_cause" : [
{
"type" : "remote_transport_exception",
"reason" : "[_Mtk082][127.0.0.1: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" : [ ],
"script" : "ctx._source.index-pattern.title = 'pddd'",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Left-hand side cannot be assigned a value."
}
}
},
"status" : 400
}

Any ideas why?

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