【发布时间】:2015-01-26 15:27:34
【问题描述】:
我正在使用 Elasticsearch 1.4.0 并尝试聚合功能。我不断收到带有 Cannot find aggregator type [fieldName] in [aggregationName] 消息的 SearchParseException。
在 JSON 格式中,我的数据如下所示。
{ "userCode": "abcd123", "response": 1 }
{ "userCode": "abcd123", "response": 1 }
{ "userCode": "abcd123", "response": 0 }
{ "userCode": "wxyz123", "response": 0 }
{ "userCode": "wxyz123", "response": 0 }
{ "userCode": "wxyz123", "response": 1 }
注意,有2个用户,abcd123和wxyz123,我只想统计每个响应1和0的次数。如果我把这个数据放到一个SQL表中,在SQL select语法中,我会做这样的事情(如果这个 SQL 示例有助于说明我正在尝试做的事情)。
select userCode, response, count(*) as total
from response_table
group by userCode, response
我希望结果集如下所示。
abcd123, 0, 1 //user abcd123 responded 0 once
abcd123, 1, 2 //user abcd123 responded 1 twice
wxyz123, 0, 2 //user wxyz123 responded 0 twice
wxyz123, 1, 1 //user wxyz123 responded 1 once
对于 Elasticsearch,我的聚合 JSON 如下所示。
{
"aggs": {
"users": {
"terms": { "field": "userCode" },
"aggs": {
"responses" : {
"terms": { "field": "response" }
}
}
}
}
}
但是,我得到了 SearchParseException:Cannot find aggregator type [responses] in [aggs]。我究竟做错了什么?
如果有帮助,我的映射文件非常简单,如下所示。
{
"data": {
"properties": {
"userCode": {
"type": "string",
"store": "yes",
"index": "analyzed",
"term_vector": "no"
},
"response": {
"type": "integer",
"store": "yes",
"index": "analyzed",
"term_vector": "yes"
}
}
}
}
【问题讨论】:
-
您发布的代码(包括映射、实际数据)对我有用。在 1.4.0 中。
标签: elasticsearch elasticsearch-aggregation