public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
   builder.startObject();
   {
     builder.startObject("shard");
     {
       builder.field("index", shard.getIndexName());
       builder.field("index_uuid", shard.getIndex().getUUID());
       builder.field("id", shard.getId());
       builder.field("primary", primary);
     }
     builder.endObject(); // end shard
     builder.field("assigned", this.assignedNodeId != null);
     // If assigned, show the node id of the node it's assigned to
     if (assignedNodeId != null) {
       builder.field("assigned_node_id", this.assignedNodeId);
     }
     builder.field("shard_state_fetch_pending", this.hasPendingAsyncFetch);
     // If we have unassigned info, show that
     if (unassignedInfo != null) {
       unassignedInfo.toXContent(builder, params);
       builder.timeValueField(
           "allocation_delay_in_millis",
           "allocation_delay",
           TimeValue.timeValueMillis(allocationDelayMillis));
       builder.timeValueField(
           "remaining_delay_in_millis",
           "remaining_delay",
           TimeValue.timeValueMillis(remainingDelayMillis));
     }
     builder.startObject("nodes");
     for (NodeExplanation explanation : nodeExplanations.values()) {
       explanation.toXContent(builder, params);
     }
     builder.endObject(); // end nodes
   }
   builder.endObject(); // end wrapping object
   return builder;
 }