Одним из способов решения выше будет получение документов и фильтрация на стороне клиента. Второй будет включать использование агрегации bucket_selector
Отображение
{
"index60" : {
"mappings" : {
"properties" : {
"plugin_instance" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"type_instance" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"value" : {
"type" : "long"
}
}
}
}
}
Данные:
"hits" : [
{
"_index" : "index60",
"_type" : "_doc",
"_id" : "vCN--3AB_Wo5Rvhl5c7f",
"_score" : 1.0,
"_source" : {
"plugin_instance" : "root-yarn-queue-name-1",
"type_instance" : "max-vcore",
"value" : 1000
}
},
{
"_index" : "index60",
"_type" : "_doc",
"_id" : "vSN--3AB_Wo5Rvhl9M6R",
"_score" : 1.0,
"_source" : {
"plugin_instance" : "root-yarn-queue-name-1",
"type_instance" : "max-mb",
"value" : 2048
}
},
{
"_index" : "index60",
"_type" : "_doc",
"_id" : "viN--3AB_Wo5Rvhl_s5m",
"_score" : 1.0,
"_source" : {
"plugin_instance" : "root-yarn-queue-name-2",
"type_instance" : "max-mb",
"value" : 3048
}
},
{
"_index" : "index60",
"_type" : "_doc",
"_id" : "wCN_-3AB_Wo5Rvhlhc53",
"_score" : 1.0,
"_source" : {
"plugin_instance" : "root-yarn-queue-name-2",
"type_instance" : "allocated-mb",
"value" : 1028
}
},
{
"_index" : "index60",
"_type" : "_doc",
"_id" : "wSOA-3AB_Wo5RvhlCc5r",
"_score" : 1.0,
"_source" : {
"plugin_instance" : "root-yarn-queue-name-1",
"type_instance" : "allocated-mb",
"value" : 3000
}
}
]
Запрос:
- Создайте сегмент из root -yarn-queue-name -. *
- Создайте вложенные сегменты ["max-mb", "alloc-mb"]
- Найдите максимальное значение из ["max-mb", "alloc-mb"]
- Найти значение alloc-mb
- Выбрать сегмент, в котором selected-mb имеет максимальное значение
{
"size": 0,
"aggs": {
"plugin_instance": {
"terms": {
"field": "plugin_instance.keyword",
"include": "root-yarn-queue-name-.*", --> pattern
"size": 10000
},
"aggs": {
"instance": {
"terms": {
"field": "type_instance.keyword",
"include": [ --> create a bucket of these two
"max-mb",
"allocated-mb"
],
"size": 10
}
},
"maxValue": {
"max": {
"field": "value"
}
},
"allocated-mb": {
"filter": {
"term": {
"type_instance.keyword": "allocated-mb"
}
},
"aggs": {
"filtered_maxValue": {
"max": {
"field": "value"
}
}
}
},
"my_bucket": {
"bucket_selector": {
"buckets_path": {
"filteredValue": "allocated-mb>filtered_maxValue",
"maxValue": "maxValue"
},
"script": "params.filteredValue==params.maxValue"
}
}
}
}
}
}
Результат:
"aggregations" : {
"plugin_instance" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "root-yarn-queue-name-1",
"doc_count" : 3,
"instance" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "allocated-mb",
"doc_count" : 1
},
{
"key" : "max-mb",
"doc_count" : 1
}
]
},
"maxValue" : {
"value" : 3000.0
},
"allocated-mb" : {
"doc_count" : 1,
"filtered_maxValue" : {
"value" : 3000.0
}
}
}
]
}
}
Дайте мне знать, если у вас есть какие-либо сомнения в этом