Partial update error. Reason: "Left-hand side cannot be assigned a value."


I'm trying to update an index-pattern in .kibana to contain another scripted field. In testing partial update of the document field I get an error. The partial update was 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][][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?

Have you tried updating this index pattern in the UI?

I'm trying to automate the creation of scripted fields, so using the UI is not an option

So that error is thrown by the Painless compiler trying to compile that script. I think it is trying to run your script rather than taking that as an update to the index-pattern. The saved object looks like this:

  "_index": ".kibana",
  "_type": "doc",
  "_id": "index-pattern:949c2fc0-0216-11e8-ba5f-d90822c14a01",
  "_version": 3,
  "found": true,
  "_source": {
    "type": "index-pattern",
    "updated_at": "2018-01-25T21:28:54.558Z",
    "index-pattern": {
      "title": "billy*",
      "fields": """[{"name":"_id","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_index","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_score","type":"number","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_source","type":"_source","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_type","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"billy","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"billy.keyword","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"script","type":"number","count":0,"scripted":true,"script":"doc['billy']","lang":"painless","searchable":true,"aggregatable":true,"readFromDocValues":false}]"""

I think you would need to update the "fields" field in the _source field and append your new scripted field to that array.

Maybe you could explain in more detail what you are trying to do.

I'm trying to do exactly as you said. Perform a partial update to update ._source.index-pattern.fields with the appended scripted field. But I believe the problem is index-pattern contains a hash-minus, so "script" : "ctx._source.index-pattern.fields" throws an error. I tried using Unicode \u002D as a replacement, but it still doesn't work.

If that is the case, you could try this style of accessing the field:
This might sort out your issue.

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