# Object field aggregations with query

**URL:** <https://discuss.elastic.co/t/object-field-aggregations-with-query/229039>\
**Category:** Elasticsearch\
**Created:** [April 21, 2020, 12:50pm UTC](https://discuss.elastic.co/t/object-field-aggregations-with-query/229039 "2020-04-21T12:50:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Striukov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_striukov/32/48782_2.png) [@Ivan\_Striukov](https://discuss.elastic.co/u/Ivan_Striukov)\
**Post date:** [April 21, 2020, 12:50pm UTC](https://discuss.elastic.co/t/object-field-aggregations-with-query/229039/1 "2020-04-21T12:50:13Z")

</div>

I have following mapping in my index. "description" field it is an array of objects and i want to aggregate only one field of one object of this array. I trying to add query for parent aggregation but it doesn`t help.

```
"country": {
          "properties": {
            "deletion": {
              "type": "boolean"
            },
            "deletionMark": {
              "type": "boolean"
            },
            "description": {
              "properties": {
                "lang": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "tittle": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            },
            "id": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        }

```

Data what i have :

```
"country": {
      "id": "a8b84f31-2d49-11dd-8608-0018fe7ab965",
      "deletion": false,
      "deletionMark": false,
      "description": [
        {
          "tittle": "China",
          "lang": "en"
        },
        {
          "tittle": "Китай",
          "lang": "ru"
        },
        {
          "tittle": "Китай",
          "lang": "uk"
        }
      ]
    }

```

My aggregation :

```
{
    "global" : { },
    "aggregations" : {
      "and" : {
        "filter" : {
          "match" : {
            "country.description.lang.keyword" : {
              "query" : "uk",
              "operator" : "OR",
              "prefix_length" : 0,
              "max_expansions" : 50,
              "fuzzy_transpositions" : true,
              "lenient" : false,
              "zero_terms_query" : "NONE",
              "auto_generate_synonyms_phrase_query" : true,
              "boost" : 1.0
            }
          }
        },
        "aggregations" : {
          "6eb5efa6-affb-11e7-80cc-009c029ad4f0" : {
            "terms" : {
              "field" : "country.description.tittle.keyword",
              "size" : 1000,
              "min_doc_count" : 1,
              "shard_min_doc_count" : 0,
              "show_term_doc_count_error" : false,
              "order" : [
                {
                  "_count" : "desc"
                },
                {
                  "_key" : "asc"
                }
              ]
            }
          }
        }
      }
    }
  } 

```

Aggregation which elastic return :

```
{
      "meta" : { },
      "doc_count" : 65039,
      "and" : {
        "meta" : { },
        "doc_count" : 1,
        "6eb5efa6-affb-11e7-80cc-009c029ad4f0" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : "China",
              "doc_count" : 1
            },
            {
              "key" : "Китай",
              "doc_count" : 1
            }
          ]
        }
      }
    }
  }

```

What aggregation i want to receive :

```
{
      "meta" : { },
      "doc_count" : 65039,
      "and" : {
        "meta" : { },
        "doc_count" : 1,
        "6eb5efa6-affb-11e7-80cc-009c029ad4f0" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : "Китай",
              "doc_count" : 1
            }
          ]
        }
      }
    }
  }

```

What i need to do for it? How i can filter object inside of aggregation?

---

<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:** [May 19, 2020, 12:50pm UTC](https://discuss.elastic.co/t/object-field-aggregations-with-query/229039/2 "2020-05-19T12:50:30Z")

</div>

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