title: ClassCastException[null] when grouping on a particular field
body: <p>I am trying to group the results on a particular field by using the following query: </p>
  
  <pre><code>{ 
    "from": 0, 
    "size": 0, 
    "fields": [ 
      "exitPage.categoryId" 
    ], 
    "aggs": { 
      "check": { 
        "terms": { 
          "field": "exitPage.categoryId" 
        } 
      } 
    } 
  }
  </code></pre>
  
  <p>Elasticsearch server throws this exception: </p>
  
  <pre><code>{ 
    "error": "ClassCastException[null]", 
    "status": 500 
  }
  </code></pre>
  
  <p>and that too, on an intermittent basis - sometimes it returns results while sometimes it does not. There is no more descriptive information available in the server log. </p>
  
  <p>Does anyone have a clue to this problem?</p>
  
  <p>Edit: Added error log as asked by <a href="https://stackoverflow.com/users/4604579/val">Val</a></p>
  
  <pre><code>[2016-02-01 12:42:28,773][DEBUG][action.search.type ] [elastic71] failed to reduce search
  org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to execute phase [fetch], [reduce]
  at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$2.onFailure(TransportSearchQueryThenFetchAction.java:159)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:41)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.ClassCastException
  </code></pre>