我正在使用elasticsearch来创建方面。它适用于计数,但我尝试更复杂的任务。问题是我不知道我想做的任务的名称....
我的实际方面查询:
"facets": {
"name": {"terms": {"field": "name", "size": 20}}
}
回应:
"name": {
"_type": "terms",
"missing": 0,
"total": 11,
"other": 0,
"terms": [
{ "term": "liliales", "count": 4 },
{ "term": "commelinales", "count": 3 },
{ "term": "dioscoreales", "count": 2 },
{ "term": "arecales", "count": 1 },
{ "term": "poales", "count": 1 }
] } }
这是我的数据的例子:
name | rank
_________________________________
liliales | accepted
liliales | accepted
liliales | misapplied
liliales | synonym
commelinales | accepted
commelinales | misapplied
commelinales | synonym
dioscoreales | misapplied
dioscoreales | synonym
arecales | accepted
poalesa | synonym
我希望每个学期都有一个计数为“等级”的子数组,如下所示:
"name" : {
"_type" : "terms",
"missing" : 0,
"total" : 11,
"other" : 0,
"terms" : [{
"term" : "liliales",
"count" : 4,
"rank" : {
"accepted" : 2,
"misapplied" : 1,
"synonym" : 1
}
}, {
"term" : "commelinales",
"count" : 3,
"rank" : {
"accepted" : 1,
"misapplied" : 1,
"synonym" : 1
}
}, {
"term" : "dioscoreales",
"count" : 2,
"rank" : {
"misapplied" : 1,
"synonym" : 1
}
}, {
"term" : "arecales",
"count" : 1,
"rank" : {
"accepted" : 1
}
}, {
"term" : "poales",
"count" : 1,
"rank" : {
"synonym" : 1
}
}
]
}
这个方面的名称是什么,请问我该怎么做?
感谢提前
答案 0 :(得分:2)
我认为您正在寻找聚合。
为构建多级聚合而构建聚合。
因此,您可以为name
设置第一个级别,然后为rank
设置另一个级别。
类似的东西:
GET _search
{
"aggs": {
"by_name": {
"terms": {
"field": "name"
},
"aggs": {
"by_rank": {
"terms": {
"field": "rank"
}
}
}
}
}
}