title: nested terms aggregation on object containing a string field
body: <p>I like to run a nested terms aggregation on string field which is inside an object.</p>
  
  <p>Usually, I use this query </p>
  
  <pre><code>      "terms": {
          "field": "fieldname.keyword"
        }
  </code></pre>
  
  <p>to enable fielddata</p>
  
  <p>But I am unable to do that for a nested document like this</p>
  
  <pre><code>{
        "nested": {
          "path": "objectField"
        },
        "aggs": {
          "allmyaggs": {
            "terms": {
              "field": "objectField.fieldName.keyword"
            }
          }
        }
      }
  </code></pre>
  
  <p>The above query is just returning an empty buckets array</p>
  
  <p>Is there a way this can be done without enabling field-data by default during index mapping.
  Since that will take a large heap memory and I have already loaded a huge data without it</p>
  
  <p>document mapping</p>
  
  <pre><code>{
    "mappings": {
      "properties": {
        "productname": {
          "type": "nested",
          "properties": {
            "productlineseqno": {
              "type": "text"
            },
            "invoiceitemname": {
              "type": "text"
            },
            "productlinename": {
              "type": "text"
            },
            "productlinedescription": {
              "type": "text"
            },
            "isprescribable": {
              "type": "boolean"
            },
            "iscontrolleddrug": {
              "type": "boolean"
            }
          }
        }
  </code></pre>
  
  <p>sample document</p>
  
  <pre><code>{
    "productname": [
      {
        "productlineseqno": "1.58",
        "iscontrolleddrug": "false",
        "productlinename": "Consultations",
        "productlinedescription": "Consultations",
        "isprescribable": "false",
        "invoiceitemname": "invoice name"
      }
    ]
  }
  </code></pre>
  
  <p>Fixed</p>
  
  <p>By changing the mapping to enable field data</p>