From 81aa483345a50884e266749c4ed1945ac3bf2612 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Mon, 4 Oct 2021 13:29:14 -0400 Subject: [PATCH] [ML] fixing minor text categorization aggregation bug (#78629) --- .../elasticsearch/xpack/ml/aggs/categorization/TreeNode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/categorization/TreeNode.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/categorization/TreeNode.java index 7b13e93d8f1ea..e74dbe8fe76ce 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/categorization/TreeNode.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/categorization/TreeNode.java @@ -252,7 +252,7 @@ void collapseTinyChildren() { return; } Optional maybeWildChild = getChild(WILD_CARD_ID).or(() -> { - if ((double) smallestChild.peek().count / this.getCount() <= 1.0 / maxChildren) { + if (smallestChild.size() > 0 && (double) smallestChild.peek().count / this.getCount() <= 1.0 / maxChildren) { TreeNode tinyChild = children.remove(smallestChild.poll().tokenId); return Optional.of(addChild(WILD_CARD_ID, tinyChild)); } @@ -267,7 +267,7 @@ void collapseTinyChildren() { smallestChild.add(tinyNode); break; } else { - wildChild.mergeWith(children.remove(tinyNode.count)); + wildChild.mergeWith(children.remove(tinyNode.tokenId)); } } }