# Query regarding aggregations in elastic search for nested objects?

**URL:** <https://discuss.elastic.co/t/query-regarding-aggregations-in-elastic-search-for-nested-objects/68415>\
**Category:** Elasticsearch\
**Created:** [December 8, 2016, 9:41am UTC](https://discuss.elastic.co/t/query-regarding-aggregations-in-elastic-search-for-nested-objects/68415 "2016-12-08T09:41:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)\
**Post date:** [December 8, 2016, 9:41am UTC](https://discuss.elastic.co/t/query-regarding-aggregations-in-elastic-search-for-nested-objects/68415/1 "2016-12-08T09:41:08Z")

</div>

I need to query the data using [aggregation.My](http://aggregation.My) questions I have nested object and I try the query but my question how to do multiple aggregation based on the field which is not in nested object.

Please find the query you may get the idea

```
GET dealytics2/deal/_search
{
  "size": 0, 
  "_source": {
    "includes": [
      "master_deal_no",
      "advisors.advisor_type"
    ]
  },
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "advisors",
            "query": {
              "bool": {
                "should": [
                  {
                    "match_phrase": {
                      "advisors.advisor_type": "Buyer advisors, non-lawyers"
                    }
                  },
                  {
                    "match_phrase": {
                      "advisors.advisor_type": "Target_advisors, non-lawyers"
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "range": {
            "rank_date": {
              "gte": "01/01/2012",
              "lte": "31/12/2013",
              "format": "dd/MM/yyyy||yyyy"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "bankers": {
      "nested": {
        "path": "advisors"
      },
      "aggs": {
        "bankers1": {
          "terms": {
            "field": "advisors.advisor"
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 8, 2016, 11:54am UTC](https://discuss.elastic.co/t/query-regarding-aggregations-in-elastic-search-for-nested-objects/68415/2 "2016-12-08T11:54:04Z")

</div>

Could you explain a bit more about the problem you are trying to solve:

- What doesn't work with the request you have provided?
- What do you documents look like?
- What do you mappings look like?
- What are you looking for as the expected result?

---

<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:** [January 5, 2017, 11:54am UTC](https://discuss.elastic.co/t/query-regarding-aggregations-in-elastic-search-for-nested-objects/68415/3 "2017-01-05T11:54:21Z")

</div>

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