elasticsearch - Get count for unique terms -
in elasticsearch, want unique terms , counts terms.
index: doc1: filetype(multivalued): pdf, zip, zip, txt expected result: pdf: 1 zip: 2 txt: 1
i made query, got error.
"aggs": { "uniqueterms": { "terms": { "field": "filetype" } }, "aggs": { "count": { "cardinality": { "field": "filetype" } } } }
how can make query result?
index mapping updated:
"file" : { "properties" : { "filetype" : { "type" : "string", "norms" : { "enabled" : false }, "fields" : { "raw" : { "type" : "string", "index" : "not_analyzed", "ignore_above" : 256 } } } } }
good start, you're there. need nest cardinality
aggregation 1 level deeper.
{ "aggs": { "uniqueterms": { "terms": { "field": "filetype" }, "aggs": { "count": { "cardinality": { "field": "filetype" } } } } } }
Comments
Post a Comment