# How to get only the required results from aggregation

**URL:** <https://discuss.elastic.co/t/how-to-get-only-the-required-results-from-aggregation/21553>\
**Category:** Elasticsearch\
**Created:** [January 9, 2015, 6:53am UTC](https://discuss.elastic.co/t/how-to-get-only-the-required-results-from-aggregation/21553 "2015-01-09T06:53:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cto](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@cto](https://discuss.elastic.co/u/cto)\
**Post date:** [January 9, 2015, 6:53am UTC](https://discuss.elastic.co/t/how-to-get-only-the-required-results-from-aggregation/21553/1 "2015-01-09T06:53:54Z")

</div>

Hi,

I have an input JSON of the format  
_{_

- "shopName": "Shop01",\*
- "address": "xyz",\*
- "rackId": "ac015",\*
- "rackProductList": [\*
- 

```
   {*

```

- 

```
       "name": "book",*

```

- 

```
       "price": 111,*

```

- 

```
       "weight": 123*

```

- 

```
   },*

```

- 

```
   {*

```

- 

```
       "name": "notebook",*

```

- 

```
       "price": 133,*

```

- 

```
       "weight": 123*

```

- 

```
   },*

```

- 

```
   {*

```

- 

```
       "name": "pencil-box",*

```

- 

```
       "price": 131,*

```

- 

```
       "weight": 123*

```

- 

```
   }*

```

- ]\*  
_}_

"rackProductList" is a nested object.  
Now, I want to get the _max price_ of _books_ across all racks.

I am using the search query  
_POST /\_search_

_{_

- "size": 0,\*
- "aggs": {\*
- 

```
   "attribute": {*

```

- 

```
       "nested": {*

```

- 

```
           "path": "rackProductList"*

```

- 

```
       },*

```

- 

```
       "aggs": {*

```

- 

```
           "group_by_name": {*

```

- 

```
               "terms": {*

```

- 

```
                   "field": "rackProductList.name"*

```

- 

```
               },*

```

- 

```
               "aggs": {*

```

- 

```
                   "max_value": {*

```

- 

```
                       "max": {*

```

- 

```
                           "field": "rackProductList.price"*

```

- 

```
                       }*

```

- 

```
                   }*

```

- 

```
               }*

```

- 

```
           }*

```

- 

```
       }*

```

- 

```
   }*

```

- }\*  
_}_

This query is returning the max-price of all the items.  
How can get only the max price value for books???  
Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/58b33bb2-58a0-47b5-9a19-25f78b45590f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/58b33bb2-58a0-47b5-9a19-25f78b45590f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:39am UTC](https://discuss.elastic.co/t/how-to-get-only-the-required-results-from-aggregation/21553/2 "2017-07-06T00:39:55Z")

</div>

Closed on July 6, 2017, 12:39am UTC


