Nested aggregation crashes cluster all the time

I have had working queries with nested aggregation before with size of millions for field and ids. But, this time I am having issue with similar nested aggregation for 2 different fields. It is crashing the cluster all the time even with the size of 20k. I tried to set the search.max_buckets to very high number also ( 9 million) so that it would throw an error instead of crashing the whole cluster. But, still it is crashing. What could be the possible reason? I noticed the JVM memory in kibana monitoring goes really high at the time of querying before crashing. I also don't know how to get a hold of log. Do I need to set up anything ? or is there a folder for it inside elasticsearch?
Thank you