Elasticsearch - Grouping aggregation - 2 fields -
my mapping is
{ "myapp": { "mappings": { "attempts": { "properties": { "answers": { "properties": { "question_id": { "type": "long" }, "status": { "type": "long" } } }, "exam_id": { "type": "long" } } } } } }
and want group question_id , status
i want know every question_id how many has status 1 or 2
p.s. 2 attempts can have same questions
first of all, need update mapping , make answers
nested field. not making nested
make answers lose correlation between question_id
field , status
field.
{ "myapp": { "mappings": { "attempts": { "properties": { "answers": { "type":"nested", <-- update here "properties": { "question_id": { "type": "long" }, "status": { "type": "long" } } }, "exam_id": { "type": "long" } } } } } }
you can use status in sub-aggregation shown below
"aggs": { "nested_qid_agg": { "nested": { "path": "answers" }, "aggs": { "qid": { "terms": { "field": "answers.question_id", "size": 0 }, "aggs": { "status": { "terms": { "field": "answers.status", "size": 0 } } } } } } }
Comments
Post a Comment