public Map<String, Object> getClusterMetrics(Map<String, Object> previousMetrics) {
        Request clusterStatRequest = new Request("GET", "_stats");
        try {
            Response response = client.getLowLevelClient().performRequest(clusterStatRequest);
            JsonNode responseNode = objectMapper.readValue(response.getEntity().getContent(), JsonNode.class);

            if (responseNode != null) {
                DocumentContext statContext = JsonPath.parse(responseNode.toString());

                Map<String, Object> metrics = new HashMap<>();

                Arrays.stream(ClusterStatMetrics.values())
                        .filter(m -> Objects.nonNull(m.getClusterStat()))
                        .forEach(metric -> {
                            String fieldName = metric.getFieldName();
                            try {
                                Object value = statContext.read(metric.getClusterStat());
                                if (value instanceof Number current && metric.isRateMetric() && previousMetrics.containsKey(fieldName)) {
                                    Number previous = (Number) previousMetrics.get(fieldName);
                                    long rate = current.longValue() - previous.longValue();
                                    if (rate > 0) {
                                        metrics.put(metric.getRateFieldName(), rate);
                                    }
                                }
                                metrics.put(fieldName, value);
                            } catch (Exception e) {
                                log.error("Could not retrieve cluster metric {}", fieldName);
                            }
                        });

                return metrics;
            }

            throw new IOException("No cluster stats returned");
        } catch (IOException e) {
            log.error("Error retrieving cluster stats", e);
        }
        return Map.of();
    }
@Test
    public void getClusterMetrics() {
        final Map<String, Object> previousMetrics = Map.of("search_ops", 5);
        Map<String, Object> clusterMetrics = collector.getClusterMetrics(previousMetrics);
        assertThat(clusterMetrics.get("doc_count")).isEqualTo(6206956);
        assertThat(clusterMetrics.get("search_ops")).isEqualTo(13);
        assertThat(clusterMetrics.get("search_ops_rate")).isEqualTo(8L);
        String[] allMetrics = Arrays.stream(ClusterStatMetrics.values()).map(ClusterStatMetrics::getFieldName).toArray(String[]::new);
        assertThat(clusterMetrics).containsKeys(allMetrics);
    }