Aggregation based on two fields in Elasticsearch results in SearchParseExcepetion with "cannot find aggregator type"

I am using Elasticsearch 1.4.0 and testing an aggregation function. I keep getting SearchParseException with the message Cannot find aggregator type [fieldName] in [aggregationName]

.

In JSON format, my data looks like this.

{ "userCode": "abcd123", "response": 1 }
{ "userCode": "abcd123", "response": 1 }
{ "userCode": "abcd123", "response": 0 }
{ "userCode": "wxyz123", "response": 0 }
{ "userCode": "wxyz123", "response": 0 }
{ "userCode": "wxyz123", "response": 1 }

      

Note that there are 2 users, abcd123

and wxyz123

, and I just want to count the number of times each answered 1 and 0. If I put this data into a SQL table, in the SQL select syntax, I would do something like this (if this the SQL example helps illustrate what I am trying to do).

select userCode, response, count(*) as total
from response_table
group by userCode, response

      

I expect the result set to look like this.

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

      

For Elasticsearch, my JSON aggregation looks like this.

{
 "aggs": {
  "users": {
   "terms": { "field": "userCode" },
   "aggs": {
    "responses" : {
     "terms": { "field": "response" }
    }
   }
  }
 }
}

      

However, I get SearchParseException: Cannot find aggregator type [responses] in [aggs]

. What am I doing wrong?

If that helps, my mapping file is very simple and looks like this.

{
  "data": {
    "properties": {
      "userCode": {
        "type": "string",
        "store": "yes",
        "index": "analyzed",
        "term_vector": "no"
      },
      "response": {
        "type": "integer",
        "store": "yes",
        "index": "analyzed",
        "term_vector": "yes"
      }
    }
  }
}

      

+3


source to share


1 answer


The following aggregation worked for me (it gave me the results I wanted), but I would still like some clarification as to why my previous approach resulted in a SearchParseException.



{
 "aggs": {
  "users": {
   "terms": { "field" : "userCode" },
   "aggs": {
    "responses": {
     "histogram": { "field": "response", "interval": 1 }
    }
   }
  }
 }
}

      

+2


source







All Articles