# Can not extract the "value" from the Aggregation

**URL:** <https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281>\
**Category:** Elasticsearch\
**Created:** [May 9, 2022, 5:51pm UTC](https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281 "2022-05-09T17:51:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cugo](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@cugo](https://discuss.elastic.co/u/cugo)\
**Post date:** [May 9, 2022, 5:51pm UTC](https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281/1 "2022-05-09T17:51:58Z")

</div>

I have a list of Buckets (parentSalaries) that has a list of Aggregations of size 2. One of the Aggregations (average\_salary) has the following fields; **value** , **name, valueAsString and metadata**. I am trying to extract the data from the " **value**" but there is no function for it. I tried to use other types of Aggregations such as `ParsedTDigestPercentiles but there is no function that can be used to extract the "value" data. Hopefully, someone can help me.

 ![0uXBe](https://us1.discourse-cdn.com/elastic/original/3X/9/2/92b757c4090cb52f96b42abb1eba5aa770248542.png)

```auto
private void doSomething(Aggregations aggregations) {
 //aggregations is the Aggregations from the SearchResponse
 Terms parentSalaryRatio = aggregations.get("parent_salary_ratio");
 if (parentSalaryRatio != null) {
            List<? extends Terms.Bucket> parentSalaries = parentSalaryRatio.getBuckets();
            getTotalAvgSalaries(parentSalaries);
        }
}

 private void getTotalAvgSalaries(List<? extends Terms.Bucket> parentSalaries) {
      Aggregations aggregations = parentSalaries.get(0).getAggregations();
      Aggregation avgSalaryAgg = aggregations.get("avg_salary");
      //No function to get the "value" out of "avgSalaryAgg"

}

```

Query

```auto
 AggregationBuilder precentials_salary = AggregationBuilders
                .percentiles("precentials_salary")
                .field("perAnnumSalary");

```

```
    AggregationBuilder average_salary = AggregationBuilders
            .avg("average_salary")
            .field("perAnnumSalary");

```

Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 10, 2022, 1:10am UTC](https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281/2 "2022-05-10T01:10:47Z")

</div>

Welcome to our community! 😃

It'd be great if you could share your query and an example response so people can see exactly what you are referring to.

---

<div class="post-metadata">

**Author:** ![cugo](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@cugo](https://discuss.elastic.co/u/cugo)\
**Post date:** [May 10, 2022, 8:55am UTC](https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281/3 "2022-05-10T08:55:53Z")

</div>

Hi Mark,

I updated the question. Hope it helps.

Thanks,  
Caglar

---

<div class="post-metadata">

**Author:** ![cugo](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@cugo](https://discuss.elastic.co/u/cugo)\
**Post date:** [May 11, 2022, 11:51am UTC](https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281/4 "2022-05-11T11:51:22Z")

</div>

I used _ParsedSingleValueNumericMetricsAggregation_ to extract the "value" data. It has the _value()_ function. The _ParsedAvg_ can be used as well. It extends _ParsedSingleValueNumericMetricsAggregation_

---

<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:** [June 8, 2022, 11:51am UTC](https://discuss.elastic.co/t/can-not-extract-the-value-from-the-aggregation/304281/5 "2022-06-08T11:51:26Z")

</div>

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