# Searching on aggregated nested fields

**URL:** https://discuss.elastic.co/t/searching-on-aggregated-nested-fields/309909
**Category:** Elasticsearch
**Created:** [July 18, 2022, 1:57pm UTC](https://discuss.elastic.co/t/searching-on-aggregated-nested-fields/309909 "2022-07-18T13:57:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Robina\_Dhingra1](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@Robina\_Dhingra1](https://discuss.elastic.co/u/Robina_Dhingra1)
#### Post date: [July 18, 2022, 1:57pm UTC](https://discuss.elastic.co/t/searching-on-aggregated-nested-fields/309909/1 "2022-07-18T13:57:23Z")

</div>

Hi Team Elastic,

We have a requirement where we created continuous transform to keep track of field status of our trades data. The transform aggregates the data and produces documents in this form -

```auto
{
        "_index": "tradebystatusarm1",
        "_id": "NgA3KmZlOSFTcdVfchLP9eGjAAAAAAAA",
        "_score": 1,
        "_source": {
          "tradeDateTime": "2022-07-08T00:00:00.000Z",
          "regulator": {
            "BaFIN": {
              "assetclass": {
                "EQUI": {
                  "accountName": {
                    "ACCOUNT1": {
                      "statuss": {
                        "NEW": {
                          "count": 1,
                          "tm": {
                            "submissionAccountName.keyword": "ACCOUNT1",
                            "assetClass.keyword": "EQUI",
                            "regulator.keyword": "BaFIN",
                            "status.keyword": "NEW"
                          }
                        },
                        "UNR": {
                          "count": 1,
                          "tm": {
                            "submissionAccountName.keyword": "ACCOUNT1",
                            "assetClass.keyword": "EQUI",
                            "regulator.keyword": "BaFIN",
                            "status.keyword": "UNR"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "executingEntityIdCode": "635400BDQCJNMOGTBB61"
        }
      },
      {
        "_index": "tradebystatusarm1",
        "_id": "NgBEtCHrC8H1qJoQ8kyg9CGVAAAAAAAA",
        "_score": 1,
        "_source": {
          "tradeDateTime": "2022-07-10T00:00:00.000Z",
          "regulator": {
            "BaFIN": {
              "assetclass": {
                "EQUI": {
                  "accountName": {
                    "ACCOUNT1": {
                      "statuss": {
                        "RPD": {
                          "count": 1,
                          "tm": {
                            "submissionAccountName.keyword": "ACCOUNT1",
                            "assetClass.keyword": "EQUI",
                            "regulator.keyword": "BaFIN",
                            "status.keyword": "RPD"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "executingEntityIdCode": "635400BDQCJNMOGTBB61"
        }
      }

```

Now this might be very obvious for experts, but I am not able to get my head around as to how to query this data ? For example, for executingEntityIdCode": "635400BDQCJNMOGTBB61", ACCOUNT1, what's the unique status count?

I understand there might be another aggregation required on top of it. But I can't seemt o get the syntax for the fillers in between that are actual values from document.

---

<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: [August 15, 2022, 1:57pm UTC](https://discuss.elastic.co/t/searching-on-aggregated-nested-fields/309909/2 "2022-08-15T13:57:43Z")

</div>

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