Scripted fields defined in kibana - when executed?

I believe @flash1293 answered your question below

scripted fields, Kibana adds a layer on top of that and remembers to attach them to each request Kibana is making on your behalf. You can't persist them directly as part the Elasticsearch index.

However if you want to persist the values of your script you can do so by defining an ingest pipeline with a script processor: https://www.elastic.co/guide/en/elasticsearch/reference/7.5/script-processor.html

This won't save the script itself, but the computed values in the Elasticsearch index. This also means you have to re-index your data if you ever change your script, but it will be much more efficient while querying data.

The post is here