# Function in defining mapping

**URL:** <https://discuss.elastic.co/t/function-in-defining-mapping/217968>\
**Category:** Elasticsearch\
**Created:** [February 5, 2020, 10:50am UTC](https://discuss.elastic.co/t/function-in-defining-mapping/217968 "2020-02-05T10:50:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antriksh\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@Antriksh\_Jain](https://discuss.elastic.co/u/Antriksh_Jain)\
**Post date:** [February 5, 2020, 10:50am UTC](https://discuss.elastic.co/t/function-in-defining-mapping/217968/1 "2020-02-05T10:50:56Z")

</div>

Think about this requirement:  
Say I've parent-child relationship as follows:  
Customer-\>Orders  
A customer can have multiple order.

I want to maintain Customer.MaxOrderTotal this field will maintain maximum price for his/her orders.  
E.g. If a customer has 3 orders of OrderTotal: $10, $15, $2 then Customer.MaxOrderTotal should hold value as $15.

I don't want to update this value each time order is indexed. Also I don't want to use aggregations in search.

Is there anyway where while defining elastic index mapping, I can configure this field should hold MAX value of order total?

Something like following:  
mappings": {  
"\_doc": {  
"properties": {  
"MaxOrderTotal": {  
"type": " **A FUNCTION INDICATING MAX OF OTHER FIELD**"  
}

I am using elastic6.3

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 4, 2020, 10:50am UTC](https://discuss.elastic.co/t/function-in-defining-mapping/217968/2 "2020-03-04T10:50:57Z")

</div>

Closed on March 4, 2020, 10:50am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
