# What is wrong with my JSON Input usage?

**URL:** <https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058>\
**Category:** Kibana\
**Created:** [April 3, 2017, 10:13pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058 "2017-04-03T22:13:29Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 3, 2017, 10:13pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/1 "2017-04-03T22:13:29Z")

</div>

Hello,

I have an index where I store some server information I pull from an http API, I'm trying to get a pie chart with the number of vcpus each of the server has available. I have to multiply the 'totalProcessorCores' by 2 to get the vcpus (threads) but for some reason I'm getting either of this messages depending of the request I'm sending to elasticsearch.

> Visualize: [parsing\_exception] Unknown key for a START\_OBJECT in [script]

```
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "analyze_wildcard": true,
            "query": "type: Server"
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": 1491195600000,
              "lte": 1491281999999,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "must_not": []
    }
  },
  "_source": {
    "excludes": []
  },
  "aggs": {
    "2": {
      "terms": {
        "field": "id.name",
        "size": 20,
        "order": {
          "_term": "desc"
        }
      },
      "aggs": {
        "1": {
          "top_hits": {
            "docvalue_fields": [
              "totalProcessorCores"
            ],
            "_source": "totalProcessorCores",
            "size": 1,
            "sort": [
              {
                "@timestamp": {
                  "order": "desc"
                }
              }
            ],
            "script": {
              "lang": "groovy",
              "inline": "doc['totalProcessorCores'].value * 2"
            }
          }
        }
      }
    }
  }
}

```

> Visualize: [parsing\_exception] Unknown key for a VALUE\_STRING in [script]

```
{
  .
  .
  .,
            "script": "doc['totalProcessorCores'].value * 2",
            "lang": "groovy"
          }
        }
      }
    }
  }
}

```

I also allowed the groovy scripts in my elasticsearch.yml and restarted the service.

```
script.engine.groovy.inline.aggs: true
script.engine.groovy.inline.search: true

```

In some posts I found googling this errors they were always related to some typo or bad use of the DSL but I don't seem to catch mine. I already checked it agains [the current docs](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-request-script-fields.html) and also tried [this example](https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542/2) with no success.

Thank you,

N

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 3, 2017, 11:39pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/2 "2017-04-03T23:39:01Z")

</div>

Can you try the following?

```auto
GET YOUR_INDEX/YOUR_DOC/_search
{
  "script_fields": {
    "my_doubled_field": {
      "script": {
        "lang": "expression",
        "inline": "doc['totalProcessorCores'] * multiplier",
        "params": {
          "multiplier": 2
        }
      }
    }
  }
} 

```

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 4, 2017, 2:38pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/3 "2017-04-04T14:38:10Z")

</div>

Hello jkuang,

Tried. Same "Unknown key for a START\_OBJECT in [script]." error shows up.

N

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 4, 2017, 8:22pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/4 "2017-04-04T20:22:58Z")

</div>

I think it's the way the doc['totalProcessorCores'] field object is being reference. The code says it can't match this object.

Can you provide your index mapping and a line of json input?

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 4, 2017, 8:43pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/5 "2017-04-04T20:43:50Z")

</div>

Sure, this is the mapping for the server type.

```
    "mappings" : {
      "Server" : {
        "dynamic" : false,
        "properties" : {
          "biosVersion" : {
            "type" : "keyword"
          },
          "coresPerProcessorSocket" : {
            "type" : "integer"
          },
          "serverPoolId" : {
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "memory" : {
            "type" : "long"
          },
          "processorType" : {
            "type" : "keyword"
          },
          "biosReleaseDate" : {
            "type" : "keyword"
          },
          "ethernetPortIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "threadsPerCore" : {
            "type" : "integer"
          },
          "serverRunState" : {
            "type" : "keyword"
          },
          "clusterId" : {
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "processorSpeed" : {
            "type" : "double"
          },
          "productName" : {
            "type" : "keyword"
          },
          "manufacturer" : {
            "type" : "keyword"
          },
          "biosVendor" : {
            "type" : "keyword"
          },
          "hostname" : {
            "type" : "keyword"
          },
          "protected" : {
            "type" : "boolean"
          },
          "networkIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "enabledProcessorCores" : {
            "type" : "integer"
          },
          "managerUuid" : {
            "type" : "keyword"
          },
          "storageInitiatorIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "ovmVersion" : {
            "type" : "keyword"
          },
          "serialNumber" : {
            "type" : "keyword"
          },
          "repositoryExportIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "totalProcessorCores" : {
            "type" : "integer"
          },
          "populatedProcessorSockets" : {
            "type" : "integer"
          },
          "vmIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "usableMemory" : {
            "type" : "long"
          },
          "storageElementIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "maintenanceMode" : {
            "type" : "boolean"
          }
        }
      },

```

About the line of json input well I just simply want to multiply that value by 2, or if it's possible by the `threadsPerCore` value which is another integer in the same type mapping, so the script I wrote in the OP stands as an example.

Thank you very much!

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 4, 2017, 8:52pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/6 "2017-04-04T20:52:34Z")

</div>

I think something is wrong with your index. I couldn't reproduce your issue. Please see my sample below using your mapping:

```auto
PUT mymulti
{
 "mappings" : {
      "Server" : {
        "dynamic" : false,
        "properties" : {
          "biosVersion" : {
            "type" : "keyword"
          },
          "coresPerProcessorSocket" : {
            "type" : "integer"
          },
          "serverPoolId" : {
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "memory" : {
            "type" : "long"
          },
          "processorType" : {
            "type" : "keyword"
          },
          "biosReleaseDate" : {
            "type" : "keyword"
          },
          "ethernetPortIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "threadsPerCore" : {
            "type" : "integer"
          },
          "serverRunState" : {
            "type" : "keyword"
          },
          "clusterId" : {
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "processorSpeed" : {
            "type" : "double"
          },
          "productName" : {
            "type" : "keyword"
          },
          "manufacturer" : {
            "type" : "keyword"
          },
          "biosVendor" : {
            "type" : "keyword"
          },
          "hostname" : {
            "type" : "keyword"
          },
          "protected" : {
            "type" : "boolean"
          },
          "networkIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "enabledProcessorCores" : {
            "type" : "integer"
          },
          "managerUuid" : {
            "type" : "keyword"
          },
          "storageInitiatorIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "ovmVersion" : {
            "type" : "keyword"
          },
          "serialNumber" : {
            "type" : "keyword"
          },
          "repositoryExportIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "totalProcessorCores" : {
            "type" : "integer"
          },
          "populatedProcessorSockets" : {
            "type" : "integer"
          },
          "vmIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "usableMemory" : {
            "type" : "long"
          },
          "storageElementIds" : {
            "type" : "nested",
            "properties" : {
              "name" : {
                "type" : "keyword"
              },
              "type" : {
                "type" : "keyword"
              },
              "value" : {
                "type" : "keyword"
              },
              "uri" : {
                "type" : "keyword"
              }
            }
          },
          "maintenanceMode" : {
            "type" : "boolean"
          }
        }
      }
 }}
 

```

```auto
 POST mymulti/Server/
 {
   "totalProcessorCores" : 2
 }

```

```auto
 GET mymulti/Server/_search
{
  "script_fields": {
    "my_doubled_field": {
      "script": {
        "lang": "expression",
        "inline": "doc['totalProcessorCores'] * multiplier",
        "params": {
          "multiplier": 2
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 4, 2017, 8:54pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/7 "2017-04-04T20:54:12Z")

</div>

Results:

```auto
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1,
    "hits": [
      {
        "_index": "mymulti",
        "_type": "Server",
        "_id": "AVs6uNoNnn3k1Vj753OV",
        "_score": 1,
        "fields": {
          "my_doubled_field": [
            4
          ]
        }
      },
      {
        "_index": "mymulti",
        "_type": "Server",
        "_id": "AVs6vWEjnn3k1Vj753OW",
        "_score": 1,
        "fields": {
          "my_doubled_field": [
            6
          ]
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 4, 2017, 9:19pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/8 "2017-04-04T21:19:17Z")

</div>

I tried your code again in the dev tools tab in kibana and it shows the same results. However I still get the errors if I try to do the same in a visualization json input. For instance,

![](https://us1.discourse-cdn.com/elastic/original/3X/7/2/72cdb9ea403e4149a329338987ac35bd76c2920c.JPG)

And in the input json I wrote:

```
{
"script": {
        "lang": "expression",
        "inline": "doc['totalProcessorCores'] * multiplier",
        "params": {
          "multiplier": 2
        }
      }
}

```

But still got the `Unknown key for a START_OBJECT in [script]` error.

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 4, 2017, 9:21pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/9 "2017-04-04T21:21:37Z")

</div>

What version of ES and Kibana are you using?

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 4, 2017, 9:23pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/10 "2017-04-04T21:23:18Z")

</div>

I'm using 5.3 for everything.

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 4, 2017, 9:27pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/11 "2017-04-04T21:27:35Z")

</div>

I'm using 5.3 too and my sample works, but it doesn't work for you. Just to confirm, you're getting the error in dev tools or in the visualization?

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 4, 2017, 9:30pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/12 "2017-04-04T21:30:34Z")

</div>

In the visualization. Here is a bigger print screen.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/1/0/10d18bf1bf5c94c3144cb0c921b438429de4f6df.JPG)

I couldn't fit the json input field in the image but you can read what I wrote 2 comments ago.

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 4, 2017, 11:22pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/13 "2017-04-04T23:22:51Z")

</div>

I'm able to reproduce your error now. This is a problem with the JSON input for sure. I even used the example from the doc and I am getting your error.

[https://www.elastic.co/guide/en/kibana/current/metric-chart.html](https://www.elastic.co/guide/en/kibana/current/metric-chart.html)

There is a workaround. You can go to Kibana \> Management \> Index Pattern \> choose your index \> click on the scripted field tab and put the script there. Then go back to visualization and choose the scripted field .

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 5, 2017, 2:47pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/14 "2017-04-05T14:47:16Z")

</div>

Hello jkuang,

Thank you very much for your help. Indeed making a new scripted field worked like a charm, do you consider a good idea to open an issue in the github page? Did you already do it by any chance?

Thank you very much again!

N

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [April 5, 2017, 4:18pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/15 "2017-04-05T16:18:28Z")

</div>

I would recommend you open an issue on github. ^^ I'm sure many people would encounter this too. Helping each other is what open source is about. 😃

---

<div class="post-metadata">

**Author:** ![Nestor\_Manrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor_manrique/32/70072_2.png) [@Nestor\_Manrique](https://discuss.elastic.co/u/Nestor_Manrique)\
**Post date:** [April 5, 2017, 4:58pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/16 "2017-04-05T16:58:07Z")

</div>

All right, I just opened an [issue](https://github.com/elastic/kibana/issues/11049) to address this matter.

Thank you again jimmy!

N

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 3, 2017, 4:58pm UTC](https://discuss.elastic.co/t/what-is-wrong-with-my-json-input-usage/81058/17 "2017-05-03T16:58:19Z")

</div>

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