Creating scripted field via API

Is it possible to create scripted filed via API PUT command? I want to use that in bash script with curl.

hmm, yea its possible, but kinda tedious:

You basically have to do a PUT to the entire index pattern object, with the scripted field added that you want.Notice how I’ve added two scripted fields at the end of the fields array.

PUT .kibana/doc/index-pattern:dd4f03e0-caf9-11e7-a4b5-a34d320f888c
{
  "type": "index-pattern",
  "updated_at": "2017-11-20T16:08:10.574Z",
  "index-pattern": {
    "title": "finance",
    "timeFieldName": "@timestamp",
    "fields": """[{"name":"@timestamp","type":"date","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"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":"account","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"account.search","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"amount","type":"number","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"day_of_month","type":"number","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"day_of_week","type":"number","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"description","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"description.search","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"month","type":"number","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"year","type":"number","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"asdf","type":"number","count":0,"scripted":true,"script":"doc['amount'].value + 1","lang":"painless","searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"sdfg","type":"number","count":0,"scripted":true,"script":"doc['amount'].value + 2","lang":"painless","searchable":true,"aggregatable":true,"readFromDocValues":false}]"""
  }
}

Thanks
Rashmi

Thank you! It was very helpful!

Am glad it helped!

Cheers
Rashmi

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