0
要求: 我想要查找特定类别ID的aID计数。 (即对于categoryID 2532,我希望计数为2,这意味着它被分配给两个aID)。使用Elasticsearch获取文档中特定字段的计数
我尝试了聚合,但我只能得到doc数而不是字段数。
映射
"List": {
"properties": {
"aId": {
"type": "long"
},
"CategoryList": {
"properties": {
"categoryId": {
"type": "long"
},
"categoryName": {
"type": "string"
}
}
}
}
}
样本文档:
"List": [
{
"aId": 33074,
"CategoryList": [
{
"categoryId": 2532,
"categoryName": "VODAFONE"
}
]
},
{
"aId": 12074,
"CategoryList": [
{
"categoryId": 2532,
"categoryName": "VODAFONE"
}
]
},
{
"aId": 120755,
"CategoryList": [
{
"categoryId": 1234,
"categoryName": "SMPLKE"
}
]
}
]
您是否尝试过['cardinality'聚集(https://www.elastic.co/导向/ EN/elasticsearch /参考/电流/搜索聚合度量基数-aggregation.html)? – Val
我会尽量让你知道.. – Seeker
你不能使用基数聚合得到你想要的结果,请检查我的答案 – user3775217