Я запрашиваю два разных запроса в одном запросе. Первый вариант — «покажи мне количество документов для subject.label для этих конкретных значений», а второй — «покажи мне количество документов для 5 наиболее распространенных значений в subject.label».
Запрос выполнен,
Код: Выделить всё
POST my_index/search
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"selected": {
"terms": {
"field": "subject.label",
"include": [ "Buddhist art" ],
"order": { "_count": "desc" },
"size": 5
}
},
"subject": {
"terms": {
"field": "subject.label",
"order": { "_count": "desc" },
"size": 5
}
}
}
}
Код: Выделить всё
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"userFacets" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Buddhist art",
"doc_count" : 12
}
]
},
"subject" : {
"doc_count_error_upper_bound" : 11,
"sum_other_doc_count" : 1005,
"buckets" : [
{
"key" : "Architecture",
"doc_count" : 88
},
{
"key" : "Painting",
"doc_count" : 80
},
{
"key" : "Berkeley (Calif.)",
"doc_count" : 25
},
{
"key" : "Buddhist art",
"doc_count" : 11
},
{
"key" : "Church architecture",
"doc_count" : 10
}
]
}
}
}
(Этот пример я взял из еще одного поста https://discuss. elastic.co/t/ Different-aggregation-count-for-the-same-value/324566)
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/784 ... same-value