I have noticed that when using DateHistograms I'm often running out of memory and my Elasticsearch is crashing. Especially with lower configured intervals. I have tried to tweak Elasticsearch circuit breaker settings but they don't seem to help much in this case.
Is there anything I can do to prevent Elasticsearch from breaking? I'm ok with an error returned from the query.
Any chance you have min_doc_count set to 0, have a large range, and have a small interval? I believe we can run out of memory in that case. I merged https://github.com/elastic/elasticsearch/pull/72081 recently to stop it from running out.
If you have something else I'd love to hear about it! Running out of memory is always a bug. Might be one we've fixed, but yeah.
The best way to file an issue is to reproduce it on an empty install with a bash script running curl. Or the kibana dev console. If you can do that the stack trace on the oom would give us a hint. But sometimes it takes detective work to from there.
Yes, I have used min_doc_count of 0 with a small interval. This means it will probably be fixed with your merged changes.
The stack trace of the exception was:
[2021-05-03T09:42:43,756][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [*] fatal error in thread [elasticsearch[*][search][T#1]], exiting
java.lang.OutOfMemoryError: Java heap space
at java.util.ArrayList.<init>(ArrayList.java:154) ~[?:?]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildAggregationsForVariableBuckets(BucketsAggregator.java:335) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregator.buildAggregations(DateHistogramAggregator.java:145) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildAggregationsForVariableBuckets(BucketsAggregator.java:330) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregator.buildAggregations(DateHistogramAggregator.java:145) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildAggregationsForSingleBucket(BucketsAggregator.java:294) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.nested.NestedAggregator.buildAggregations(NestedAggregator.java:127) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForAllBuckets(BucketsAggregator.java:236) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator.access$700(GlobalOrdinalsStringTermsAggregator.java:65) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$StandardTermsResults.buildSubAggs(GlobalOrdinalsStringTermsAggregator.java:720) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$StandardTermsResults.buildSubAggs(GlobalOrdinalsStringTermsAggregator.java:670) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$ResultStrategy.buildAggregations(GlobalOrdinalsStringTermsAggregator.java:586) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$ResultStrategy.access$200(GlobalOrdinalsStringTermsAggregator.java:535) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator.buildAggregations(GlobalOrdinalsStringTermsAggregator.java:193) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForAllBuckets(BucketsAggregator.java:236) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator.access$700(GlobalOrdinalsStringTermsAggregator.java:65) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$StandardTermsResults.buildSubAggs(GlobalOrdinalsStringTermsAggregator.java:720) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$StandardTermsResults.buildSubAggs(GlobalOrdinalsStringTermsAggregator.java:670) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$ResultStrategy.buildAggregations(GlobalOrdinalsStringTermsAggregator.java:586) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$ResultStrategy.access$200(GlobalOrdinalsStringTermsAggregator.java:535) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator.buildAggregations(GlobalOrdinalsStringTermsAggregator.java:193) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForAllBuckets(BucketsAggregator.java:236) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator.access$700(GlobalOrdinalsStringTermsAggregator.java:65) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$StandardTermsResults.buildSubAggs(GlobalOrdinalsStringTermsAggregator.java:720) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$StandardTermsResults.buildSubAggs(GlobalOrdinalsStringTermsAggregator.java:670) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$ResultStrategy.buildAggregations(GlobalOrdinalsStringTermsAggregator.java:586) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$ResultStrategy.access$200(GlobalOrdinalsStringTermsAggregator.java:535) ~[elasticsearch-7.9.1.jar:7.9.1]
That one is different! It looks like it happened on the data node rather than the coordinating node. So it'll be a little trickier to reproduce. I've filed https://github.com/elastic/elasticsearch/issues/72619 to tackle it.
The last two queries will result in the following exception:
[2021-05-04T12:51:39,411][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [*] fatal error in thread [elasticsearch[*][search][T#2]], exiting
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3689) ~[?:?]
at java.util.ArrayList.grow(ArrayList.java:238) ~[?:?]
at java.util.ArrayList.grow(ArrayList.java:243) ~[?:?]
at java.util.ArrayList.add(ArrayList.java:518) ~[?:?]
at java.util.ArrayList$ListItr.add(ArrayList.java:1098) ~[?:?]
at org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram.addEmptyBuckets(InternalDateHistogram.java:417) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram.reduce(InternalDateHistogram.java:441) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:258) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:268) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation.reduce(InternalSingleBucketAggregation.java:112) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:258) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.search.aggregations.InternalAggregations.topLevelReduce(InternalAggregations.java:202) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.SearchPhaseController.reduceAggs(SearchPhaseController.java:543) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:519) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:423) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.SearchPhaseController$2.reduce(SearchPhaseController.java:807) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:116) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.FetchSearchPhase.access$000(FetchSearchPhase.java:47) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:95) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:44) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:710) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.9.1.jar:7.9.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.ArrayList.<init>(ArrayList.java:154)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildAggregationsForVariableBuckets(BucketsAggregator.java:335)
at org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregator.buildAggregations(DateHistogramAggregator.java:145)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildAggregationsForSingleBucket(BucketsAggregator.java:294)
at org.elasticsearch.search.aggregations.bucket.nested.NestedAggregator.buildAggregations(NestedAggregator.java:127)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForAllBuckets(BucketsAggregator.java:236)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator.access$300(NumericTermsAggregator.java:58)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$StandardTermsResultStrategy.buildSubAggs(NumericTermsAggregator.java:288)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$StandardTermsResultStrategy.buildSubAggs(NumericTermsAggregator.java:268)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$ResultStrategy.buildAggregations(NumericTermsAggregator.java:188)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$ResultStrategy.access$200(NumericTermsAggregator.java:151)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator.buildAggregations(NumericTermsAggregator.java:128)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForBuckets(BucketsAggregator.java:173)
at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.buildSubAggsForAllBuckets(BucketsAggregator.java:236)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator.access$300(NumericTermsAggregator.java:58)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$StandardTermsResultStrategy.buildSubAggs(NumericTermsAggregator.java:288)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$StandardTermsResultStrategy.buildSubAggs(NumericTermsAggregator.java:268)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$ResultStrategy.buildAggregations(NumericTermsAggregator.java:188)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator$ResultStrategy.access$200(NumericTermsAggregator.java:151)
at org.elasticsearch.search.aggregations.bucket.terms.NumericTermsAggregator.buildAggregations(NumericTermsAggregator.java:128)
at org.elasticsearch.search.aggregations.Aggregator.buildTopLevel(Aggregator.java:160)
at org.elasticsearch.search.aggregations.AggregationPhase.execute(AggregationPhase.java:128)
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:156)
at org.elasticsearch.indices.IndicesService.lambda$loadIntoContext$22(IndicesService.java:1393)
at org.elasticsearch.indices.IndicesService$$Lambda$3337/0x0000000100b46040.accept(Unknown Source)
at org.elasticsearch.indices.IndicesService.lambda$cacheShardLevelResult$23(IndicesService.java:1445)
at org.elasticsearch.indices.IndicesService$$Lambda$3338/0x0000000100b46440.get(Unknown Source)
at org.elasticsearch.indices.IndicesRequestCache$Loader.load(IndicesRequestCache.java:176)
at org.elasticsearch.indices.IndicesRequestCache$Loader.load(IndicesRequestCache.java:159)
at org.elasticsearch.common.cache.Cache.computeIfAbsent(Cache.java:433)
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.