It's irrelevant what you select as "Field", because the script will overwrite this value.
However it is highly recommended to do this during ingest time for performance reasons - check with the people controlling your Elasticsearch cluster. It's even possible to configure this without an additional service by using ingest processors in Elasticsearch itself.
Edit: after more analysis, it seems that in the query generated by the view, the "Field" specified for the aggregation is not ignored, but is used in the aggregation as "field" parameter. If I execute that query, this field "wins" over the script, so the resulting value is null.
If that doesn't help, could you share the complete request and response as shown in the inspect panel? Additionally you could check whether there are some documents where this script doesn't work and returns NaN or something like this.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.