Take a look at Scripted Fields. I believe these will do what you want. You can do aggregations on them as well.
Note that these are computed on-the-fly, and are potentially more resource-intensive. The better option, if you can do it, is to add another field to the record at index time that contains the correct value. That way, it's already there and indexed by Elasticsearch.
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.