Object field aggregations with query

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?

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