ClassCastException[null] when grouping on a particular field

I am trying to group the results on a particular field by using the following query:

{ "from": 0, "size": 0, "fields": [ "exitPage.categoryId" ], "aggs": { "check": { "terms": { "field": "exitPage.categoryId" } } } }

Elasticsearch server throws this exception:

{ "error": "ClassCastException[null]", "status": 500 }

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.

Does anyone have a clue to this problem?

to solve this, mapping document is required.

Are you running that accross multiple indices?

Could be a mapping issue.

Are you sure you don't have a full stack trace?

Which version?

  • No, I am not running it across multiple indices.
  • Yes, I did not have a full stack trace for that particular exception. I faced a new exception after posting this question and the trace is as below:

[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

  • The version is 1.7.3

Upgrade if possible. IIRC lot of things have been fixed since then.

i guess some fields are conflicted.
so index mapping information is needed.

Please find the document mapping here:

i received it.
i think mapping information is correct.
and i tested it (ES 1.7.2 and 2.1). but no error..

I got the instance restarted and this fixed the issue.

I assume that it was some corrupt cache / index internally which got cleaned up once the instance was restarted.