Hello, I have an index that has more than 15M records of website logs but while I'm trying to do an aggregation to sum the total of some fields the request takes a long time more than 10 seconds and after that gives me an error
{
"statusCode": 502,
"error": "Bad Gateway",
"message": "socket hang up"
And the following query is:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"day": {
"gte": "2024-04-03",
"lte": "2024-04-04",
"format": "yyyy-MM-dd"
}
}
},
{
"term": {
"country_alias": "kw"
}
}
]
}
},
"aggs": {
"entities": {
"terms": {
"field": "entity_title",
"size": 100000
},
"aggs": {
"records": {
"top_hits": {
"size": 1,
"_source": {
"includes": [
"entity_id",
"entity_type",
"entity_title",
"country_alias",
"main_taxonomy",
"main_taxonomy_title",
"owner_phone",
"created_at",
"updated_at"
]
}
}
},
"total_visits": {
"sum": {
"script": {
"lang": "painless",
"source": "doc['visit_ios_count'].value + doc['visit_android_count'].value + doc['visit_huawei_count'].value + doc['visit_web_count'].value"
}
}
},
"total_calls": {
"sum": {
"script": {
"lang": "painless",
"source": "doc['call_ios_count'].value + doc['call_android_count'].value + doc['call_huawei_count'].value + doc['call_web_count'].value"
}
}
},
"total_whatsapp": {
"sum": {
"script": {
"lang": "painless",
"source": "doc['whatsapp_ios_count'].value + doc['whatsapp_android_count'].value + doc['whatsapp_huawei_count'].value + doc['whatsapp_web_count'].value"
}
}
},
"total_chat": {
"sum": {
"script": {
"lang": "painless",
"source": "doc['chat_ios_count'].value + doc['chat_android_count'].value + doc['chat_huawei_count'].value + doc['chat_web_count'].value"
}
}
}
}
}
}
Can any one help me to fix this issue?