Hi @BenB196,
firstly - thanks for reaching out.
We are using ES in version 7.17.6, cluster has 23 nodes (17 data nodes: 1TB storage, 64GB RAM, 3 client and 3 master nodes).
Reproducing full scenario might be very complex (using query template with facets, highlighting, mapping contains 100+ fields).
So I have isolated only required 27 fields used in 14 aggregations.
Mapping
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"refresh_interval": "10s",
"default_pipeline": "treaty_ingestion_pipeline"
},
"mappings": {
"dynamic_date_formats": [
"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||ordinal_date_time_no_millis||date_optional_time"
],
"date_detection": true,
"numeric_detection": false,
"properties": {
"content": {
"properties": {
"DOC_DOC_NM": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"null_value": "NULL_VALUE",
"ignore_above": 2000
}
}
},
"DOC_DEAL_NO": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 2000,
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 2000
},
"hash": {
"type": "murmur3"
}
}
},
"ACCP_TYP_OF_AGRMNT_DESC_LV2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"ignore_above": 2000
}
}
},
"ACCP_TYP_OF_AGRMNT_DESC_LV3": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"ignore_above": 2000
}
}
},
"ACCP_MAIN_LOB_ID_LST": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 2000
}
}
},
"ACCP_ACCP_PRFT_CNTR_DESC": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 2000
}
}
},
"ACCP_ACCP_PRFT_CNTR_DESC_LV1": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_ACCP_PRFT_CNTR_DESC_LV2": {
"type": "keyword",
"eager_global_ordinals": true,
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 256
}
}
},
"ACCP_ACCP_PRFT_CNTR_DESC_LV3": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_ACCP_PRFT_CNTR_DESC_LV4": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_ACCP_PRFT_CNTR_DESC_LV5": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_UWRT_YR": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 2000
}
}
},
"ACCP_UWRT_OBJ_STAT_DESC": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 1020
}
}
},
"ACCP_TYP_OF_AGRMNT_DESC": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 1020
}
}
},
"ACCP_MAIN_BRKR_CTRY": {
"type": "text",
"fields": {
"keyword": {
"null_value": "NULL_VALUE",
"type": "keyword",
"eager_global_ordinals": true,
"ignore_above": 1024
}
}
},
"ACCP_MAIN_BRKR_LGL_CCAT": {
"type": "text",
"fields": {
"keyword": {
"null_value": "NULL_VALUE",
"eager_global_ordinals": true,
"type": "keyword",
"ignore_above": 256
}
}
},
"ACCP_MAIN_CARR_LGL_CCAT": {
"type": "text",
"fields": {
"keyword": {
"null_value": "NULL_VALUE",
"eager_global_ordinals": true,
"type": "keyword",
"ignore_above": 256
}
}
},
"ACCP_MAIN_CLI_CCAT": {
"type": "keyword",
"null_value": "NULL_VALUE",
"ignore_above": 2000,
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 2000
}
}
},
"ACCP_MAIN_CLI_CTRY": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 1020
}
}
},
"ACCP_BUS_PARTIC_TYP_DESC": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 1020
}
}
},
"ACCP_BUS_PARTIC_TYP_DESC_LV1": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_BUS_PARTIC_TYP_DESC_LV2": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_BUS_PARTIC_TYP_DESC_LV3": {
"type": "keyword",
"eager_global_ordinals": true
},
"ACCP_MAIN_CLI_GRP_LGL_NM": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"eager_global_ordinals": true,
"null_value": "NULL_VALUE",
"ignore_above": 1020
}
}
}
}
}
}
}
}
simple aggregations (0.3s)
GET treaty_v4/_search?human=true
{
"profile": true,
"size": 0,
"aggs": {
"partners": {
"terms": {
"field": "content.ACCP_MAIN_CLI_CCAT.keyword",
"order": {
"_key": "asc"
},
"size": 500
}
},
"profitCenters": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV1",
"size": 10
},
"aggs": {
"profitCenters_lv2": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV2",
"size": 20
},
"aggs": {
"profitCenters_lv3": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV3",
"size": 100
},
"aggs": {
"profitCenters_lv4": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV4",
"size": 100
},
"aggs": {
"profitCenters_lv5": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV5",
"size": 100
}
}
}
}
}
}
}
}
}
},
"lobIdList": {
"terms": {
"field": "content.ACCP_MAIN_LOB_ID_LST.keyword",
"order": {
"_key": "asc"
},
"size": 500
}
},
"clientCountry": {
"terms": {
"field": "content.ACCP_MAIN_CLI_CTRY.keyword",
"order": {
"_key": "asc"
},
"size": 1000
}
},
"typeOfBusiness": {
"terms": {
"field": "content.ACCP_BUS_PARTIC_TYP_DESC_LV1",
"size": 10
},
"aggs": {
"typeOfBusiness_lv2": {
"terms": {
"field": "content.ACCP_BUS_PARTIC_TYP_DESC_LV2",
"size": 20
},
"aggs": {
"typeOfBusiness_lv3": {
"terms": {
"field": "content.ACCP_BUS_PARTIC_TYP_DESC_LV3",
"size": 20
}
}
}
}
}
},
"clientGroup": {
"terms": {
"field": "content.ACCP_MAIN_CLI_GRP_LGL_NM.keyword",
"order": {
"_key": "asc"
},
"size": 1000
}
},
"reinsurer": {
"terms": {
"field": "content.ACCP_MAIN_CARR_LGL_CCAT.keyword",
"order": {
"_key": "asc"
},
"size": 250
}
},
"broker": {
"terms": {
"field": "content.ACCP_MAIN_BRKR_LGL_CCAT.keyword",
"order": {
"_key": "asc"
},
"size": 1000
}
},
"brokerCountry": {
"terms": {
"field": "content.ACCP_MAIN_BRKR_CTRY.keyword",
"order": {
"_key": "asc"
},
"size": 150
}
},
"division": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV2",
"order": {
"_key": "asc"
},
"size": 50
}
},
"uwrtYear": {
"terms": {
"field": "content.ACCP_UWRT_YR.keyword",
"order": {
"_key": "desc"
},
"size": 150
}
},
"uwrtStatus": {
"terms": {
"field": "content.ACCP_UWRT_OBJ_STAT_DESC.keyword",
"order": {
"_key": "asc"
},
"size": 50
}
},
"typeOfAgreement": {
"terms": {
"field": "content.ACCP_TYP_OF_AGRMNT_DESC_LV2.keyword",
"order": {
"_key": "asc"
},
"size": 10
},
"aggs": {
"typeOfAgreement_lv3": {
"terms": {
"field": "content.ACCP_TYP_OF_AGRMNT_DESC_LV3.keyword",
"size": 20
}
}
}
},
"dealIds": {
"terms": {
"field": "content.DOC_DEAL_NO.keyword",
"order": {
"_key": "asc"
},
"size": 100
}
}
}
}
sub-aggregations (2.4s)
GET index/_search?human=true
{
"profile": true,
"size": 0,
"aggs": {
"partners": {
"terms": {
"field": "content.ACCP_MAIN_CLI_CCAT.keyword",
"order": {
"_key": "asc"
},
"size": 500
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"profitCenters": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV1",
"size": 10
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"profitCenters_lv2": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV2",
"size": 20
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"profitCenters_lv3": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV3",
"size": 100
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"profitCenters_lv4": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV4",
"size": 100
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"profitCenters_lv5": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV5",
"size": 100
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
}
}
}
}
}
}
}
}
},
"lobIdList": {
"terms": {
"field": "content.ACCP_MAIN_LOB_ID_LST.keyword",
"order": {
"_key": "asc"
},
"size": 500
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"clientCountry": {
"terms": {
"field": "content.ACCP_MAIN_CLI_CTRY.keyword",
"order": {
"_key": "asc"
},
"size": 1000
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"typeOfBusiness": {
"terms": {
"field": "content.ACCP_BUS_PARTIC_TYP_DESC_LV1",
"size": 10
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"typeOfBusiness_lv2": {
"terms": {
"field": "content.ACCP_BUS_PARTIC_TYP_DESC_LV2",
"size": 20
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"typeOfBusiness_lv3": {
"terms": {
"field": "content.ACCP_BUS_PARTIC_TYP_DESC_LV3",
"size": 20
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
}
}
}
}
},
"contentType": {
"terms": {
"field": "content.DOC_CNTNT_CLSFCN.keyword",
"order": {
"_key": "asc"
},
"size": 20
}
},
"clientGroup": {
"terms": {
"field": "content.ACCP_MAIN_CLI_GRP_LGL_NM.keyword",
"order": {
"_key": "asc"
},
"size": 1000
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"reinsurer": {
"terms": {
"field": "content.ACCP_MAIN_CARR_LGL_CCAT.keyword",
"order": {
"_key": "asc"
},
"size": 250
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"broker": {
"terms": {
"field": "content.ACCP_MAIN_BRKR_LGL_CCAT.keyword",
"order": {
"_key": "asc"
},
"size": 1000
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"brokerCountry": {
"terms": {
"field": "content.ACCP_MAIN_BRKR_CTRY.keyword",
"order": {
"_key": "asc"
},
"size": 150
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"activityGroup": {
"terms": {
"field": "content.DOC_ACTIV_GRP_TYP_LST.keyword",
"order": {
"_key": "asc"
},
"size": 50
}
},
"division": {
"terms": {
"field": "content.ACCP_ACCP_PRFT_CNTR_DESC_LV2",
"order": {
"_key": "asc"
},
"size": 50
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"uwrtYear": {
"terms": {
"field": "content.ACCP_UWRT_YR.keyword",
"order": {
"_key": "desc"
},
"size": 150
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"uwrtStatus": {
"terms": {
"field": "content.ACCP_UWRT_OBJ_STAT_DESC.keyword",
"order": {
"_key": "asc"
},
"size": 50
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
},
"typeOfAgreement": {
"terms": {
"field": "content.ACCP_TYP_OF_AGRMNT_DESC_LV2.keyword",
"order": {
"_key": "asc"
},
"size": 10
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
},
"typeOfAgreement_lv3": {
"terms": {
"field": "content.ACCP_TYP_OF_AGRMNT_DESC_LV3.keyword",
"size": 20
},
"aggs": {
"deals_count": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": "3000"
}
}
}
}
}
},
"dealIds": {
"terms": {
"field": "content.DOC_DEAL_NO.keyword",
"order": {
"_key": "asc"
},
"size": 100
}
},
"dealsCount": {
"cardinality": {
"field": "content.DOC_DEAL_NO.hash",
"precision_threshold": 40000
}
},
"dealCards": {
"aggs": {
"deal_document_names": {
"terms": {
"field": "content.DOC_DOC_NM.keyword",
"size": 20
}
},
"deal_representant": {
"top_hits": {
"_source": {
"includes": [
"content.ACCP_ACCP_PRFT_CNTR_DESC",
"content.ACCP_ACCP_PRFT_CNTR_DESC_LV2",
"content.ACCP_BUS_PARTIC_TYP_DESC",
"content.ACCP_MAIN_BRKR_CTRY",
"content.ACCP_MAIN_BRKR_LGL_CCAT",
"content.ACCP_MAIN_CARR_LGL_CCAT",
"content.ACCP_MAIN_CLI_CCAT",
"content.ACCP_MAIN_CLI_CTRY",
"content.ACCP_MAIN_CLI_GRP_LGL_NM",
"content.ACCP_MAIN_LOB_ID_LST",
"content.ACCP_TYP_OF_AGRMNT_DESC",
"content.ACCP_UWRT_OBJ_STAT_DESC",
"content.ACCP_UWRT_YR",
"content.DOC_DEAL_NO"
]
},
"size": 1
}
}
},
"composite": {
"size": 20,
"sources": [
{
"dealId": {
"terms": {
"field": "content.DOC_DEAL_NO"
}
}
}
],
"after": {
"dealId": ""
}
}
}
}
}
Regarding data, its quite tricky to share (data privacy + appropriate distribution)

Profile responses over the index with "eager_global_ordinals": true
are having 10MB and 52MB so very hard to share them.
So sharing just examples from one of the shards and one agg.:
profile of simple aggregations - profitCenters
{
"type" : "StringTermsAggregatorFromFilters",
"description" : "profitCenters",
"time" : "69.7ms",
"time_in_nanos" : 69730132,
"breakdown" : {
"reduce" : 0,
"post_collection_count" : 1,
"build_leaf_collector" : 69053246,
"build_aggregation" : 671619,
"build_aggregation_count" : 1,
"build_leaf_collector_count" : 19,
"post_collection" : 1482,
"initialize" : 3785,
"initialize_count" : 1,
"reduce_count" : 0,
"collect" : 0,
"collect_count" : 0
},
"debug" : {
"delegate" : "FilterByFilterAggregator",
"delegate_debug" : {
"segments_with_deleted_docs" : 0,
"filters" : [
{
"results_from_metadata" : 0,
"query" : "content.ACCP_ACCP_PRFT_CNTR_DESC_LV1:Group Finance",
"specialized_for" : "term"
},
{
"results_from_metadata" : 0,
"query" : "content.ACCP_ACCP_PRFT_CNTR_DESC_LV1:Group Underwriting",
"specialized_for" : "term"
},
{
"results_from_metadata" : 0,
"query" : "content.ACCP_ACCP_PRFT_CNTR_DESC_LV1:OU Corporate Solutions",
"specialized_for" : "term"
},
{
"results_from_metadata" : 0,
"query" : "content.ACCP_ACCP_PRFT_CNTR_DESC_LV1:OU Reinsurance",
"specialized_for" : "term"
}
],
"segments_counted" : 0,
"segments_with_doc_count_field" : 0,
"segments_collected" : 19
},
"built_buckets" : 1
},
"children" : [
{
"type" : "GlobalOrdinalsStringTermsAggregator",
"description" : "profitCenters_lv2",
"time" : "96.8ms",
"time_in_nanos" : 96884845,
"breakdown" : {
"reduce" : 0,
"post_collection_count" : 1,
"build_leaf_collector" : 6939080,
"build_aggregation" : 655973,
"build_aggregation_count" : 1,
"build_leaf_collector_count" : 76,
"post_collection" : 637,
"initialize" : 2242,
"initialize_count" : 1,
"reduce_count" : 0,
"collect" : 89286913,
"collect_count" : 267417
},
"debug" : {
"segments_with_multi_valued_ords" : 0,
"collection_strategy" : "remap using many bucket ords packed using [3/61] bits",
"segments_with_single_valued_ords" : 76,
"total_buckets" : 8,
"built_buckets" : 4,
"result_strategy" : "terms",
"has_filter" : false
},
"children" : [
{
"type" : "GlobalOrdinalsStringTermsAggregator",
"description" : "profitCenters_lv3",
"time" : "66.3ms",
"time_in_nanos" : 66350266,
"breakdown" : {
"reduce" : 0,
"post_collection_count" : 1,
"build_leaf_collector" : 5499671,
"build_aggregation" : 646200,
"build_aggregation_count" : 1,
"build_leaf_collector_count" : 76,
"post_collection" : 484,
"initialize" : 1327,
"initialize_count" : 1,
"reduce_count" : 0,
"collect" : 60202584,
"collect_count" : 267417
},
"debug" : {
"segments_with_multi_valued_ords" : 0,
"collection_strategy" : "remap using many bucket ords",
"segments_with_single_valued_ords" : 76,
"total_buckets" : 45,
"built_buckets" : 8,
"result_strategy" : "terms",
"has_filter" : false
},
"children" : [
{
"type" : "GlobalOrdinalsStringTermsAggregator",
"description" : "profitCenters_lv4",
"time" : "39.1ms",
"time_in_nanos" : 39197952,
"breakdown" : {
"reduce" : 0,
"post_collection_count" : 1,
"build_leaf_collector" : 3875097,
"build_aggregation" : 608910,
"build_aggregation_count" : 1,
"build_leaf_collector_count" : 76,
"post_collection" : 339,
"initialize" : 679,
"initialize_count" : 1,
"reduce_count" : 0,
"collect" : 34712927,
"collect_count" : 267417
},
"debug" : {
"segments_with_multi_valued_ords" : 0,
"collection_strategy" : "remap using many bucket ords",
"segments_with_single_valued_ords" : 76,
"total_buckets" : 120,
"built_buckets" : 45,
"result_strategy" : "terms",
"has_filter" : false
},
"children" : [
{
"type" : "GlobalOrdinalsStringTermsAggregator",
"description" : "profitCenters_lv5",
"time" : "23.9ms",
"time_in_nanos" : 23943806,
"breakdown" : {
"reduce" : 0,
"post_collection_count" : 1,
"build_leaf_collector" : 2066387,
"build_aggregation" : 471748,
"build_aggregation_count" : 1,
"build_leaf_collector_count" : 76,
"post_collection" : 153,
"initialize" : 87,
"initialize_count" : 1,
"reduce_count" : 0,
"collect" : 21405431,
"collect_count" : 267370
},
"debug" : {
"segments_with_multi_valued_ords" : 0,
"collection_strategy" : "remap using many bucket ords",
"segments_with_single_valued_ords" : 76,
"total_buckets" : 366,
"built_buckets" : 120,
"result_strategy" : "terms",
"has_filter" : false
}
}
]
}
]
}
]
}
]
},
I have also the script averaging the response times for all shards: