# How ElasticSearch do nested range aggregation query

**URL:** https://discuss.elastic.co/t/how-elasticsearch-do-nested-range-aggregation-query/48747
**Category:** Elasticsearch
**Created:** [April 28, 2016, 11:11pm UTC](https://discuss.elastic.co/t/how-elasticsearch-do-nested-range-aggregation-query/48747 "2016-04-28T23:11:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Rajiv\_Srivastava](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajiv_srivastava/32/31135_2.png) [@Rajiv\_Srivastava](https://discuss.elastic.co/u/Rajiv_Srivastava)
#### Post date: [April 28, 2016, 11:11pm UTC](https://discuss.elastic.co/t/how-elasticsearch-do-nested-range-aggregation-query/48747/1 "2016-04-28T23:11:25Z")

</div>

\*\* I am trying to aggregate and find price ranges if on the basis of nested offer price array (nested Array) object of sellerInfoES. Internal field is "offerPrice". How I can write aggregation on the nested array field in Elasticsearch. I tried this following query, but it's not working. Getting this error: Parse Failure [Found two aggregation type definitions in [price\_ranges]: [nested] and [filter]]

**Mapping:**

```
{
   "productsearch": {
      "mappings": {
         "product": {
            "properties": {
               "brand": {
                  "type": "string"
               },
               "categories": {
                  "type": "string"
               },
               "model": {
                  "type": "string"
               },
               "mrp": {
                  "type": "double"
               },
               "productName": {
                  "type": "string"
               },
               "rating": {
                  "type": "double"
               },
               "reviewCount": {
                  "type": "long"
               },
               "sellerInfoES": {
                  "type": "nested",
                  "properties": {
                     "addr": {
                        "type": "string"
                     },
                     "country": {
                        "type": "string"
                     },
                     "geoAddress": {
                        "type": "string"
                     },
                     "location": {
                        "type": "string"
                     },
                     "offerPrice": {
                        "type": "double"
                     },
                     "pinCode": {
                        "type": "string"
                     },
                     "sellerId": {
                        "type": "long"
                     },
                     "sellerLocation": {
                        "type": "geo_point"
                     },
                     "state": {
                        "type": "string"
                     }
                  }
               },
               "sku": {
                  "type": "long"
               },
               "subCategory": {
                  "type": "string"
               }
            }
         }
      }
   }
}

```

**Query:**

```
{
  "price_ranges": {
    "nested": {
      "path": "sellerInfoES"
    },
    "aggs": {
      "range": {
        "field": "offerPrice",
        "ranges": [
          {
            "gte": 1000
          },
          {
            "gte": 1000,
            "lte": 10000
          },
          {
            "gte": 10000,
            "lte": 25000
          },
          {
            "gte": 25000
          }
        ]
      }
    }
  }
}
```

---

<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 5, 2017, 10:55pm UTC](https://discuss.elastic.co/t/how-elasticsearch-do-nested-range-aggregation-query/48747/2 "2017-07-05T22:55:23Z")

</div>


