# Nested aggregation Error

**URL:** <https://discuss.elastic.co/t/nested-aggregation-error/327451>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 10, 2023, 11:58am UTC](https://discuss.elastic.co/t/nested-aggregation-error/327451 "2023-03-10T11:58:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vivek\_Burman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vivek_burman/32/118310_2.png) [@Vivek\_Burman](https://discuss.elastic.co/u/Vivek_Burman)\
**Post date:** [March 10, 2023, 11:58am UTC](https://discuss.elastic.co/t/nested-aggregation-error/327451/1 "2023-03-10T11:58:25Z")

</div>

So, I have my mappings as this  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/4/848dfafb4707f020696d22568e5425ad8f9d68e1.png)  
and my query request object as referred to `[this link](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html)`

Query JSON

```auto
{
    "size": 0,
    "query": {
        "nested": {
            "path": "custom_fields",
            "query": {
                "bool": {
                    "must": [
                        {
                            "match": {
                                "custom_fields.label": "Application Module"
                            }
                        }
                    ]
                }
            }
        }
    },
    "aggs": {
        "agg_custom_field": {
            "nested": {
                "path": "custom_fields"
            }
        },
        "aggs": {
          "agg_value": {
              "cardinality": {
                "field": "custom_fields.value"
            }
          }
        }
    }
}

```

Error Response

```auto
{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "Unknown aggregation type [agg_value]",
                "line": 26,
                "col": 24
            }
        ],
        "type": "parsing_exception",
        "reason": "Unknown aggregation type [agg_value]",
        "line": 26,
        "col": 24,
        "caused_by": {
            "type": "named_object_not_found_exception",
            "reason": "[26:24] unknown field [agg_value]"
        }
    },
    "status": 400
}

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [March 10, 2023, 1:50pm UTC](https://discuss.elastic.co/t/nested-aggregation-error/327451/2 "2023-03-10T13:50:01Z")

</div>

Hi @Vivek_Burman

Try this:

```auto
"aggs": {
    "agg_custom_field": {
      "nested": {
        "path": "custom_fields"
      },
      "aggs": {
        "agg_value": {
          "cardinality": {
            "field": "custom_fields.value"
          }
        }
      }
    }
  }

```

---

<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:** [April 7, 2023, 1:50pm UTC](https://discuss.elastic.co/t/nested-aggregation-error/327451/3 "2023-04-07T13:50:09Z")

</div>

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