在elasticsearch中,我想要获得唯一的术语以及该术语的数量。
index: doc1: filetype(multivalued): pdf, zip, zip, txt expected result: pdf: 1 zip: 2 txt: 1
I made this query, but I got an error.
"aggs": {
"uniqueTerms": {
"terms": {
"field": "filetype"
}
},
"aggs": {
"count": {
"cardinality": {
"field": "filetype"
}
}
}
}
如何查询以获得结果?
索引映射已更新:
"file" : {
"properties" : {
"filetype" : {
"type" : "string",
"norms" : {
"enabled" : false
},
"fields" : {
"raw" : {
"type" : "string",
"index" : "not_analyzed",
"ignore_above" : 256
}
}
}
}
}
最佳答案
好的开始,您快到了。您只需要将cardinality
聚合嵌套更深一层。
{
"aggs": {
"uniqueTerms": {
"terms": {
"field": "filetype"
},
"aggs": {
"count": {
"cardinality": {
"field": "filetype"
}
}
}
}
}
}
关于elasticsearch - 获得独特条款的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39114043/