# Max aggregation in transforms

**URL:** <https://discuss.elastic.co/t/max-aggregation-in-transforms/245159>\
**Category:** Elasticsearch\
**Created:** [August 16, 2020, 6:45pm UTC](https://discuss.elastic.co/t/max-aggregation-in-transforms/245159 "2020-08-16T18:45:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjilinga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anjilinga/32/86010_2.png) [@anjilinga](https://discuss.elastic.co/u/anjilinga)\
**Post date:** [August 16, 2020, 6:45pm UTC](https://discuss.elastic.co/t/max-aggregation-in-transforms/245159/1 "2020-08-16T18:45:39Z")

</div>

Hi,

In transform, i have created one max field with the below script, but when the documents are not present it is returning as null value and getting fail.  
can you please suggest how to handle it.  
"MaxHandlingDuration" :{  
"max": {  
"script": {  
"lang": "painless",  
"source": """  
if(doc['CallActionName'].size() \> 0 ){  
if(doc['CallActionName'].value=='CallHandlingComplete' )  
{  
doc.Duration.value  
}  
}  
"""  
}  
}  
}

---

<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:** [September 13, 2020, 6:45pm UTC](https://discuss.elastic.co/t/max-aggregation-in-transforms/245159/2 "2020-09-13T18:45:49Z")

</div>

Closed on September 13, 2020, 6:45pm UTC

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