0

我正在尝试使用以下查询对特定字段的结果进行分组:

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

Elasticsearch 服务器抛出此异常:

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

这也是间歇性的 - 有时它会返回结果,而有时它不会。服务器日志中没有更多的描述性信息。

有人知道这个问题吗?

编辑:按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
4

2 回答 2

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.

于 2016-02-01T12:57:09.563 回答
0

您会遇到该异常,因为您的某些文档没有exitPage属性,因此聚合器无法获取categoryId这些文档的值。

为了防止这种情况,您需要做的是过滤掉没有exitPage属性的文档,例如通过使用exists查询。

{
  "from": 0,
  "size": 0,
  "query": {                        <--- add this query
    "filtered": {
      "filter": {
        "exists": {
          "field": "exitPage"
        }
      }
    }
  },
  "aggs": {
    "check": {
      "terms": {
        "field": "exitPage.categoryId"
      }
    }
  }
}
于 2016-02-01T07:27:28.157 回答