title: Frequency count aggregation of nested elements in elastic search returning zero results
body: <p>i am trying to make an aggregation query to count the number of elements in a nested on elastic search. Here is part of the mapping:</p>
  <pre><code> {
    &quot;news&quot; : {
      &quot;aliases&quot; : { },
      &quot;mappings&quot; : {
        &quot;dynamic&quot; : &quot;false&quot;,
        &quot;properties&quot; : {
          &quot;categories&quot; : {
            &quot;type&quot; : &quot;nested&quot;,
            &quot;properties&quot; : {
              &quot;categoryId&quot; : {
                &quot;type&quot; : &quot;text&quot;
              },
              &quot;name&quot; : {
                &quot;type&quot; : &quot;text&quot;
              },
              &quot;slug&quot; : {
                &quot;type&quot; : &quot;text&quot;
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  <p>Here is the query i did:</p>
  <pre><code>{   
      &quot;size&quot;: 0,
      &quot;aggs&quot;:{
          &quot;categories_count&quot;:{
              &quot;terms&quot;: {
                  &quot;field&quot;:&quot;categories.slug.keyword&quot;,
                  &quot;size&quot;: 100
              }
          }
      }
  }
  </code></pre>
  <p>here is the result i am getting:</p>
  <pre><code>{
      &quot;took&quot;: 8,
      &quot;timed_out&quot;: false,
      &quot;_shards&quot;: {
          &quot;total&quot;: 1,
          &quot;successful&quot;: 1,
          &quot;skipped&quot;: 0,
          &quot;failed&quot;: 0
      },
      &quot;hits&quot;: {
          &quot;total&quot;: {
              &quot;value&quot;: 22,
              &quot;relation&quot;: &quot;eq&quot;
          },
          &quot;max_score&quot;: null,
          &quot;hits&quot;: []
      },
      &quot;aggregations&quot;: {
          &quot;categories_count&quot;: {
              &quot;doc_count_error_upper_bound&quot;: 0,
              &quot;sum_other_doc_count&quot;: 0,
              &quot;buckets&quot;: []
          }
      }
  }
  </code></pre>
  <p>Here is what i am trying to achieve:
  say that there are two documents:</p>
  <p>doc 1 categories:</p>
  <pre><code>&quot;categories&quot; : [
        {
          &quot;categoryId&quot; : &quot;aaaaffff&quot;,
          &quot;name&quot; : &quot;Category 1&quot;,
          &quot;slug&quot; : &quot;category-1&quot;,
        },
        {
          &quot;categoryId&quot; : &quot;aaaafffd&quot;,
          &quot;name&quot; : &quot;Category 2&quot;,
          &quot;slug&quot; : &quot;category-2&quot;,
        },
        {
          &quot;categoryId&quot; : &quot;aaaafffc&quot;,
          &quot;name&quot; : &quot;Category 3&quot;,
          &quot;slug&quot; : &quot;category-3&quot;,
        }
      ],
  </code></pre>
  <p>Doc 2 categories:</p>
  <pre><code>&quot;categories&quot; : [
            {
              &quot;categoryId&quot; : &quot;aaaafffd&quot;,
              &quot;name&quot; : &quot;Category 2&quot;,
              &quot;slug&quot; : &quot;category-2&quot;,
            },
            {
              &quot;categoryId&quot; : &quot;aaaafffc&quot;,
              &quot;name&quot; : &quot;Category 3&quot;,
              &quot;slug&quot; : &quot;category-3&quot;,
            },
            {
              &quot;categoryId&quot; : &quot;aaaafffb&quot;,
              &quot;name&quot; : &quot;Category 4&quot;,
              &quot;slug&quot; : &quot;category-4&quot;,
            },
            {
              &quot;categoryId&quot; : &quot;aaaafffe&quot;,
              &quot;name&quot; : &quot;Category 5&quot;,
              &quot;slug&quot; : &quot;category-5&quot;,
            },
          ],
  </code></pre>
  <p>Output should be something similar to this:</p>
  <pre><code>{
      {
          &quot;categoryId&quot;: &quot;aaaaffff&quot;,
          &quot;name&quot;: &quot;Category 1&quot;,
          &quot;slug&quot;: &quot;category-1&quot;,
          &quot;count&quot;: 1
      },
      {
          &quot;categoryId&quot;: &quot;aaaafffd&quot;,
          &quot;name&quot;: &quot;Category 2&quot;,
          &quot;slug&quot;: &quot;category-2&quot;,
          &quot;count&quot;: 2
      },
      {
          &quot;categoryId&quot;: &quot;aaaafffc&quot;,
          &quot;name&quot;: &quot;Category 3&quot;,
          &quot;slug&quot;: &quot;category-3&quot;,
          &quot;count&quot;: 2
      },
      {
          &quot;categoryId&quot;: &quot;aaaafffb&quot;,
          &quot;name&quot;: &quot;Category 4&quot;,
          &quot;slug&quot;: &quot;category-4&quot;,
          &quot;count&quot;: 1
      },
      {
          &quot;categoryId&quot;: &quot;aaaafffe&quot;,
          &quot;name&quot;: &quot;Category 5&quot;,
          &quot;slug&quot;: &quot;category-5&quot;,
          &quot;count&quot;: 1
      }
  }
  </code></pre>
  <p>Is there any query that can achieve that? thank you in advance. Also is it possible without changing the mapping? because i cannot change the mapping (its from management).</p>