private Map<String, Object> getIndexInformation(IndexStats stats) {
    Map<String, Object> info = Maps.newHashMap();
    info.put("docs", stats.getPrimaries().getDocs().getCount());
    info.put("size", stats.getPrimaries().getStore().getSize().getKb());
    info.put(
        "time_index", stats.getPrimaries().getIndexing().getTotal().getIndexTime().getSeconds());
    info.put("time_query", stats.getPrimaries().getSearch().getTotal().getQueryTime().getSeconds());
    info.put("time_fetch", stats.getPrimaries().getSearch().getTotal().getFetchTime().getSeconds());
    info.put("time_get", stats.getPrimaries().getGet().getTime().getSeconds());
    info.put("shards", getShardInformation(stats));

    return info;
  }
  private List<Map<String, Object>> getShardInformation(IndexStats stats) {
    List<Map<String, Object>> shards = Lists.newArrayList();
    for (Map.Entry<Integer, IndexShardStats> s : stats.getIndexShards().entrySet()) {
      Iterator<ShardStats> iter = s.getValue().iterator();
      while (iter.hasNext()) {
        ShardStats ss = iter.next();

        Map<String, Object> shard = Maps.newHashMap();

        shard.put("node_hostname", cluster.nodeIdToHostName(ss.getShardRouting().currentNodeId()));
        shard.put("node_name", cluster.nodeIdToName(ss.getShardRouting().currentNodeId()));
        shard.put("id", ss.getShardId());
        shard.put("node_id", ss.getShardRouting().currentNodeId());
        shard.put("primary", ss.getShardRouting().primary());
        shard.put("is_initializing", ss.getShardRouting().initializing());
        shard.put("is_started", ss.getShardRouting().started());
        shard.put("is_unassigned", ss.getShardRouting().unassigned());
        shard.put("is_relocating", ss.getShardRouting().relocating());
        shard.put("relocating_to", cluster.nodeIdToName(ss.getShardRouting().relocatingNodeId()));

        shards.add(shard);
      }
    }

    return shards;
  }
  @Override
  protected void beforeIndexDeletion() throws Exception {
    super.beforeIndexDeletion();
    assertBusy(
        () -> {
          IndicesStatsResponse stats = client().admin().indices().prepareStats().clear().get();
          for (IndexStats indexStats : stats.getIndices().values()) {
            for (IndexShardStats indexShardStats : indexStats.getIndexShards().values()) {
              Optional<ShardStats> maybePrimary =
                  Stream.of(indexShardStats.getShards())
                      .filter(s -> s.getShardRouting().active() && s.getShardRouting().primary())
                      .findFirst();
              if (maybePrimary.isPresent() == false) {
                continue;
              }
              ShardStats primary = maybePrimary.get();
              final SeqNoStats primarySeqNoStats = primary.getSeqNoStats();
              assertThat(
                  primary.getShardRouting() + " should have set the global checkpoint",
                  primarySeqNoStats.getGlobalCheckpoint(),
                  not(equalTo(SequenceNumbersService.UNASSIGNED_SEQ_NO)));
              for (ShardStats shardStats : indexShardStats) {
                final SeqNoStats seqNoStats = shardStats.getSeqNoStats();
                assertThat(
                    shardStats.getShardRouting() + " local checkpoint mismatch",
                    seqNoStats.getLocalCheckpoint(),
                    equalTo(primarySeqNoStats.getLocalCheckpoint()));

                assertThat(
                    shardStats.getShardRouting() + " global checkpoint mismatch",
                    seqNoStats.getGlobalCheckpoint(),
                    equalTo(primarySeqNoStats.getGlobalCheckpoint()));
                assertThat(
                    shardStats.getShardRouting() + " max seq no mismatch",
                    seqNoStats.getMaxSeqNo(),
                    equalTo(primarySeqNoStats.getMaxSeqNo()));
              }
            }
          }
        });
  }
 public void addIndex(IndexStats index) {
   indices.put(index.getIndex(), index);
 }