# Scripted field with curl

**URL:** <https://discuss.elastic.co/t/scripted-field-with-curl/106837>\
**Category:** Kibana\
**Created:** [November 8, 2017, 9:53am UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837 "2017-11-08T09:53:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumpelblase](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kumpelblase/32/35709_2.png) [@kumpelblase](https://discuss.elastic.co/u/kumpelblase)\
**Post date:** [November 8, 2017, 9:53am UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/1 "2017-11-08T09:53:20Z")

</div>

Is it possible to add a scripted filed to an index with curl or in the Kibana console? If yes please post a link or give an example.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [November 8, 2017, 2:13pm UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/2 "2017-11-08T14:13:26Z")

</div>

Hello,  
You can just add them from index page in Kibana management tab.  
[https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

---

<div class="post-metadata">

**Author:** ![kumpelblase](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kumpelblase/32/35709_2.png) [@kumpelblase](https://discuss.elastic.co/u/kumpelblase)\
**Post date:** [November 8, 2017, 2:25pm UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/3 "2017-11-08T14:25:34Z")

</div>

Yes I know, but the problem is that I would have to type many many scripted fields in by hand. If I could add scripted fields with curl, I can create the scripts with an other script like python.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [November 8, 2017, 2:38pm UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/4 "2017-11-08T14:38:25Z")

</div>

Ah, there is no supported method to do this or API, but you could update the document corresponding to the index pattern that you want to add the field to, in the `.kibana` index.

The field description is pretty much a JSON object like this:

```auto
  {
    "name": "scripted_field",
    "type": "number",
    "count": 0,
    "scripted": true,
    "script": "script",
    "lang": "painless",
    "searchable": true,
    "aggregatable": true,
    "readFromDocValues": false
  }

```

Fair warning, this is a hack-y method and not supported by Kibana as you can break your index pattern.

---

<div class="post-metadata">

**Author:** ![kumpelblase](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kumpelblase/32/35709_2.png) [@kumpelblase](https://discuss.elastic.co/u/kumpelblase)\
**Post date:** [November 8, 2017, 2:48pm UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/5 "2017-11-08T14:48:47Z")

</div>

So if I type `GET /.kibana/_search/?type=index-pattern` into the Kibana console, I get all indices, each with its fields. There are also the scripted fields included. What would be the command to get something that looks like your JSON:

> {  
> "name": "scripted\_field",  
> "type": "number",  
> "count": 0,  
> "scripted": true,  
> "script": "script",  
> "lang": "painless",  
> "searchable": true,  
> "aggregatable": true,  
> "readFromDocValues": false  
> }

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [November 8, 2017, 4:01pm UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/6 "2017-11-08T16:01:08Z")

</div>

You parse the `GET /.kibana/_search/?type=index-pattern`, get the ID of the doc that contains the index pattern that you're looking for and then get that specific document. For example `GET .kibana/doc/index-pattern:e40f5330-c48a-11e7-b160-370cb382691c`

Then, in this result you look for the value of \_source/index-pattern/fields which will be an array of objects like the scripted field one. You add your scripted field there and the you update the document: [https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-update.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-update.html)

---

<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:** [December 6, 2017, 4:01pm UTC](https://discuss.elastic.co/t/scripted-field-with-curl/106837/7 "2017-12-06T16:01:35Z")

</div>

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