How can I update visState value of a Visualization via ElasticSearch API?

I want to update my Kibana chart by update .kibana index.
Here is what I'm doing:

POST .kibana/doc/visualization:fdf49d50-2c2c-11e8-8116-8b096c761d1b/_update
{
"script": "ctx._source.visualization.visState = params.visState",
"params": {
"visState": "{"title":"Global Performance Status","type":"gauge","params": {"addLegend": true,"addTooltip": true,"gauge": {"backStyle":"Full","colorSchema":"Green to Red","colorsRange": [{"from": 0,"to": 168},{"from": 168,"to": 268},{"from": 268,"to": 400} ],"extendRange": true,"gaugeColorMode":"Labels","gaugeStyle":"Full","gaugeType":"Arc","invertColors": false,"labels": {"color":"black","show": true },"orientation":"vertical","percentageMode": false,"scale": {"color":"#333","labels": false,"show": true },"style": {"bgColor": false,"bgFill":"#eee","bgMask": false,"bgWidth": 0.9,"fontSize": 60,"labelColor": true,"mask": false,"maskBars": 50,"subText":"","width": 0.9 },"type":"meter","verticalSplit": false},"isDisplayWarning": false,"type":"gauge" },"aggs": [{"id":"1","enabled": true,"type":"avg","schema":"metric","params": {"field":"durationmilliseconds","customLabel":"Global Average Duration (ms)"}}]}"
}
}

I got updated status, but field visState is empty when I check it in Management \ Kibana \ Objects \ Saved Visualizations.

Could you please help me.

image
image

Since you already have the ID of the visualization, and the full vizState text to replace the document with, why not just do a plain partial-doc update instead of a scripted update?

Example:

POST /.kibana/doc/visualization:8a17bb40-3200-11e8-afcf-71409930d828/_update
{
  "doc": {
    "visualization": {
      "title": "My Gauge",
      "visState": """{"title":"My Gauge","type":"gauge","params":{"type":"gauge","addTooltip":true,"addLegend":true,"isDisplayWarning":false,"gauge":{"verticalSplit":false,"extendRange":true,"percentageMode":false,"gaugeType":"Arc","gaugeStyle":"Full","backStyle":"Full","orientation":"vertical","colorSchema":"Green to Red","gaugeColorMode":"Labels","colorsRange":[{"from":0,"to":50},{"from":50,"to":75},{"from":75,"to":100}],"invertColors":false,"labels":{"show":true,"color":"black"},"scale":{"show":true,"labels":false,"color":"#333"},"type":"meter","style":{"bgWidth":0.9,"width":0.9,"mask":false,"bgMask":false,"maskBars":50,"bgFill":"#eee","bgColor":false,"subText":"","fontSize":60,"labelColor":true}}},"aggs":[{"id":"1","enabled":true,"type":"count","schema":"metric","params":{}}]}"""
    }
  }
}

Also, take care that the visState text is surrounded by triple-quotes in Dev Tools. It needs to be a string, not an object.

Oh, I didn't realize that.

Thank you, Tim.

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