Script fields are a feature which produce field values on the fly for the top N documents that match the given query. They are not useable in other parts of the API. In particular, since they are only calculated for top N, it would not be possible to use them for aggregations which operate on every document the query matches.
You will need to duplicate your script inside your sum aggregation. There is a documented example using a script for a sum aggregation which may help. To avoid duplication, you could also store the script and reference in both locations by name.
Thanks for the answer.
We tried to do this, use scripts inside the aggregation, it turned out to be too slow, in the end we abandoned this idea, and transferred the calculation logic to the application.
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.