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][ ] [elastic71] failed to reduce search Failed to execute phase [fetch], [reduce] at$AsyncAction$2.onFailure( at at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at 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.