# Extract Max value of build number from result and use it in filter value

**URL:** <https://discuss.elastic.co/t/extract-max-value-of-build-number-from-result-and-use-it-in-filter-value/103864>\
**Category:** Kibana\
**Created:** [October 13, 2017, 9:28am UTC](https://discuss.elastic.co/t/extract-max-value-of-build-number-from-result-and-use-it-in-filter-value/103864 "2017-10-13T09:28:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajinkya\_Sabale](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Ajinkya\_Sabale](https://discuss.elastic.co/u/Ajinkya_Sabale)\
**Post date:** [October 13, 2017, 9:28am UTC](https://discuss.elastic.co/t/extract-max-value-of-build-number-from-result-and-use-it-in-filter-value/103864/1 "2017-10-13T09:28:11Z")

</div>

I want to extract Max build\_number from following and apply filter on that max. build number.

Query in dev tools-  
GET logstash-report-2017.10.13/\_search?filter\_path=hits.hits.\_source.build\_number

Result is -

{  
"hits": {  
"hits": [  
{  
"\_source": {  
"build\_number": "271278"  
}  
},  
{  
"\_source": {  
"build\_number": "271317"  
}  
},  
{  
"\_source": {  
"build\_number": "271317"  
}  
},  
{  
"\_source": {  
"build\_number": "271317"  
}  
},  
{  
"\_source": {  
"build\_number": "271317"  
}  
},  
{  
"\_source": {  
"build\_number": "271317"  
}  
},  
{  
"\_source": {  
"build\_number": "271278"  
}  
},  
{  
"\_source": {  
"build\_number": "271278"  
}  
},  
{  
"\_source": {  
"build\_number": "271278"  
}  
},  
{  
"\_source": {  
"build\_number": "271278"  
}  
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![Ajinkya\_Sabale](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Ajinkya\_Sabale](https://discuss.elastic.co/u/Ajinkya_Sabale)\
**Post date:** [October 13, 2017, 10:14am UTC](https://discuss.elastic.co/t/extract-max-value-of-build-number-from-result-and-use-it-in-filter-value/103864/2 "2017-10-13T10:14:01Z")

</div>

I got max value from this query, but how to use this in visualizations buckets ?

GET logstash-report-2017.10.13/\_search  
{  
"aggs" : {  
"max\_id" : { "max" : { "field" : "build\_number" } }  
}  
}

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [October 13, 2017, 6:45pm UTC](https://discuss.elastic.co/t/extract-max-value-of-build-number-from-result-and-use-it-in-filter-value/103864/3 "2017-10-13T18:45:31Z")

</div>

Right now there's no way to create a query that uses the results of a previous request in an automated fashion. Those sorts of multi-stage queries are something we'd like to explore in the future.

If you just want to create a bucket for the max build number that you can then add sub-buckets to, you might be able to hack this together.

Create a new vis with a "Max build\_number" metric on the y-axis. Create a "Split Chart" bucket with a terms agg of size 1 on the build\_number field, ordered by the max metric. Now add whatever additional metrics and buckets you want. I think that's about as close as you'll get currently. See example below.

 ![31 PM](https://us1.discourse-cdn.com/elastic/original/3X/4/e/4eab8c1abc9e886449e91039542db6d24fc99b1a.png)

---

<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:** [November 10, 2017, 6:45pm UTC](https://discuss.elastic.co/t/extract-max-value-of-build-number-from-result-and-use-it-in-filter-value/103864/4 "2017-11-10T18:45:33Z")

</div>

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