# Create document with values from parent aggregation and sub aggregation

**URL:** <https://discuss.elastic.co/t/create-document-with-values-from-parent-aggregation-and-sub-aggregation/311954>\
**Category:** Logstash\
**Created:** [August 11, 2022, 5:02pm UTC](https://discuss.elastic.co/t/create-document-with-values-from-parent-aggregation-and-sub-aggregation/311954 "2022-08-11T17:02:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [August 11, 2022, 5:02pm UTC](https://discuss.elastic.co/t/create-document-with-values-from-parent-aggregation-and-sub-aggregation/311954/1 "2022-08-11T17:02:08Z")

</div>

Hi, Im queriyng elastic with logstash, exec input, and a bash script with curl.

this is the response:

```auto
"aggregations" : {
    "parent-agg" : {
      "buckets" : [
        {
          "key" : "one",
          "sub-aggs-two" : {
            "buckets" : [
              {
                "key" : "A-one",
              },
              {
                "key" : "B-one",
              }
            ]
          }
        },
        {
          "key" : "two",
          "sub-aggs-two" : {
            "buckets" : [
              {
                "key" : "A-two",
              },
              {
                "key" : "B-two",
              }
            ]
          }
        }
      ]
   }
}

```

I know that I can get the parent-agg key value (one and two) with this filter:

```auto

    split {
      field => "[aggregations][parent-agg][buckets]"
    }

    mutate {
       add_field => {
           "my_parent_field" => "%{[aggregations][parent-agg][buckets][key]}"
       }
    }

```

So I get two documents:

```auto
{ "my_parent_field : "one" }
{ "my_parent_field : "two" }

```

but I need to create this documents

```auto
{ "my_parent_field : "one", "my_child_field" : "A-one"},
{ "my_parent_field : "one", "my_child_field" : "B-one"},
{ "my_parent_field : "two" , "my_child_field" : "A-two"},
{ "my_parent_field : "two" , "my_child_field" : "B-two"},

```

How I can do this?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 11, 2022, 5:50pm UTC](https://discuss.elastic.co/t/create-document-with-values-from-parent-aggregation-and-sub-aggregation/311954/2 "2022-08-11T17:50:38Z")

</div>

What does an event returned by that aggregation look like?

---

<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:** [September 8, 2022, 5:51pm UTC](https://discuss.elastic.co/t/create-document-with-values-from-parent-aggregation-and-sub-aggregation/311954/3 "2022-09-08T17:51:03Z")

</div>

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