diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersFeatureSet.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersFeatureSet.java index e5bca6c6001fc..5028c36c8b37d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersFeatureSet.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTiersFeatureSet.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; +import org.elasticsearch.action.admin.indices.stats.IndexShardStats; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNodeRole; @@ -117,16 +118,19 @@ private DataTiersFeatureSetUsage.TierSpecificStats calculateStats(List { - nodeStats.getIndices().getShardStats(index).stream() - .filter(shardStats -> shardStats.getPrimary().getStore() != null) - .forEach(shardStats -> { - StoreStats primaryStoreStats = shardStats.getPrimary().getStore(); - // If storeStats is null, it means this is not a replica - primaryShardCount.incrementAndGet(); - long primarySize = primaryStoreStats.getSizeInBytes(); - primaryByteCount.addAndGet(primarySize); - valueSketch.add(primarySize); - }); + final List allShardStats = nodeStats.getIndices().getShardStats(index); + if (allShardStats != null) { + allShardStats.stream() + .filter(shardStats -> shardStats.getPrimary().getStore() != null) + .forEach(shardStats -> { + StoreStats primaryStoreStats = shardStats.getPrimary().getStore(); + // If storeStats is null, it means this is not a replica + primaryShardCount.incrementAndGet(); + long primarySize = primaryStoreStats.getSizeInBytes(); + primaryByteCount.addAndGet(primarySize); + valueSketch.add(primarySize); + }); + } }); } }