title: How to aggregate a 'non - keyword' field in elasticsearch?
body: <p>I am trying to write an elastic-search query that should list all distinct values held by various fields in a document.When the fields are of type Keyword,the term aggregate query works fine and I can see the values with their counts listed in the buckets.But, I don't get any result when I query for the distinct citrus fruit types, the  mapping is as shown below:</p>
  
  <pre><code>{   
      "vegetables":{
        "type": "text",
        "fields": {
           "keyword" : {
              "type" : "keyword",
              "ignore_above": 256
            }
          }
       }, 
      "fruits": {
          "properties": {
              "citrus": {
                  "properties": {
                      "orange": {
                          "type": "long"
                      },
                      "lemon": {
                          "type": "long"
                      },
                      "kiwi": {
                          "type": "long"
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>and the result I am expecting is :</p>
  
  <pre><code>"aggregations": {
    "distinct_citrusy_fruits"{
       "buckets" : [
         {
           "key":"oranges",
           "doc_count": 23
         },
         {
           "key":"lemon",
           "doc_count": 21
         },
         {
           "key":"kiwi",
           "doc_count": 23
         }
        ]
     }
  }
  </code></pre>
  
  <p>when I make a term aggregation for the "vegetables" field (which is a keyword type) i am able to get the buckets as above. 
  How to get the distinct counts in this case?Also, I don't have the option to change the document format.</p>
  
  <p>EDIT- the only workaround I have found till now is to call the mappings api and then parse the nested JSON in my code to get the key values,if there is any better solution possible, please add an answer here.</p>