0

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?

Edit: Added error log as asked by Val

[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
Community
  • 1
  • 1
Ankur
  • 2,171
  • 23
  • 29

2 Answers2

0

You're getting that exception because some of your documents don't have an exitPage property and hence the aggregator cannot get the categoryId value for those documents.

What you need to do in order to prevent this, is to filter out the documents that don't have an exitPage property, for instance by using an exists query.

{
  "from": 0,
  "size": 0,
  "query": {                        <--- add this query
    "filtered": {
      "filter": {
        "exists": {
          "field": "exitPage"
        }
      }
    }
  },
  "aggs": {
    "check": {
      "terms": {
        "field": "exitPage.categoryId"
      }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • This did not work... Three states - 1) Result, 2) { "error": "ReduceSearchPhaseException[Failed to execute phase [fetch], [reduce] ]; nested: ClassCastException; ", "status": 503 } 3) { "error": "ClassCastException[null]", "status": 500 } – Ankur Feb 01 '16 at 07:41
  • There must be something logged in your ES logs. Can you share that (in your question maybe so you can paste the full output)? – Val Feb 01 '16 at 07:43
0

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. If someone knows a better explanation, do edit this post.

Ankur
  • 2,171
  • 23
  • 29