The UI is updating the
index-pattern saved object with the new scripted field data. You could perform these steps programmatically. You can open the developer tools in your browser and add a scripted field to an index-pattern. The network tab will capture the interactions with the server so you can see how the UI is using Kibana's saved object API.
Use the saved object GET API to retrieve the
index-pattern saved object
Add your scripted field to
attributes. fields. Fields is just a JSON array that has been serialized into a string for storage. Convert the string into JSON, add your scripted field to the array and then serialize back to a string.
Use the saved object update API to update the
index-pattern saved object.