How to get only the required results from aggregation

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/58b33bb2-58a0-47b5-9a19-25f78b45590f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.