IndexSegments(String index, ShardSegments[] shards) {
    this.index = index;

    Map<Integer, List<ShardSegments>> tmpIndexShards = Maps.newHashMap();
    for (ShardSegments shard : shards) {
      List<ShardSegments> lst = tmpIndexShards.get(shard.shardRouting().id());
      if (lst == null) {
        lst = Lists.newArrayList();
        tmpIndexShards.put(shard.shardRouting().id(), lst);
      }
      lst.add(shard);
    }
    indexShards = Maps.newHashMap();
    for (Map.Entry<Integer, List<ShardSegments>> entry : tmpIndexShards.entrySet()) {
      indexShards.put(
          entry.getKey(),
          new IndexShardSegments(
              entry.getValue().get(0).shardRouting().shardId(),
              entry.getValue().toArray(new ShardSegments[entry.getValue().size()])));
    }
  }