Skip to content

Commit 8612080

Browse files
authored
Don't use #getSourceAsMap when reading TopHits in transform (#119623)
Using this method will cache the generated object which can increase the memory usage for quite a bit.
1 parent 92bb091 commit 8612080

File tree

1 file changed

+8
-1
lines changed
  • x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/latest

1 file changed

+8
-1
lines changed

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/latest/Latest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.elasticsearch.ElasticsearchException;
1111
import org.elasticsearch.action.ActionListener;
1212
import org.elasticsearch.client.internal.Client;
13+
import org.elasticsearch.common.bytes.BytesReference;
14+
import org.elasticsearch.common.xcontent.XContentHelper;
1315
import org.elasticsearch.index.query.BoolQueryBuilder;
1416
import org.elasticsearch.index.query.QueryBuilders;
1517
import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -90,7 +92,12 @@ private static Map<String, Object> convertBucketToDocument(
9092
topHits.getHits().getHits().length
9193
);
9294
}
93-
Map<String, Object> document = topHits.getHits().getHits()[0].getSourceAsMap();
95+
96+
// We don't use #getSourceAsMap here because we don't want to cache the object as we
97+
// only need it here. More over we are modifying the map of maps so we will be holding
98+
// the wrong map.
99+
BytesReference bytes = topHits.getHits().getHits()[0].getSourceRef();
100+
Map<String, Object> document = XContentHelper.convertToMap(bytes, true).v2();
94101

95102
// generator to create unique but deterministic document ids, so we
96103
// - do not create duplicates if we re-run after failure

0 commit comments

Comments
 (0)