Nested aggregation Error

So, I have my mappings as this
image
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

{
    "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

{
    "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
}

Hi @Vivek_Burman

Try this:

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

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