@Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   this.index = in.readOptionalString();
   this.shard = in.readOptionalVInt();
   this.primary = in.readOptionalBoolean();
   this.includeYesDecisions = in.readBoolean();
 }
 @Override
 public SearchSourceBuilder readFrom(StreamInput in) throws IOException {
   SearchSourceBuilder builder = new SearchSourceBuilder();
   if (in.readBoolean()) {
     int size = in.readVInt();
     List<BytesReference> aggregations = new ArrayList<>(size);
     for (int i = 0; i < size; i++) {
       aggregations.add(in.readBytesReference());
     }
     builder.aggregations = aggregations;
   }
   builder.explain = in.readOptionalBoolean();
   builder.fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
   boolean hasFieldDataFields = in.readBoolean();
   if (hasFieldDataFields) {
     int size = in.readVInt();
     List<String> fieldDataFields = new ArrayList<>(size);
     for (int i = 0; i < size; i++) {
       fieldDataFields.add(in.readString());
     }
     builder.fieldDataFields = fieldDataFields;
   }
   boolean hasFieldNames = in.readBoolean();
   if (hasFieldNames) {
     int size = in.readVInt();
     List<String> fieldNames = new ArrayList<>(size);
     for (int i = 0; i < size; i++) {
       fieldNames.add(in.readString());
     }
     builder.fieldNames = fieldNames;
   }
   builder.from = in.readVInt();
   if (in.readBoolean()) {
     builder.highlightBuilder = in.readBytesReference();
   }
   boolean hasIndexBoost = in.readBoolean();
   if (hasIndexBoost) {
     int size = in.readVInt();
     ObjectFloatHashMap<String> indexBoost = new ObjectFloatHashMap<String>(size);
     for (int i = 0; i < size; i++) {
       indexBoost.put(in.readString(), in.readFloat());
     }
     builder.indexBoost = indexBoost;
   }
   if (in.readBoolean()) {
     builder.innerHitsBuilder = in.readBytesReference();
   }
   if (in.readBoolean()) {
     builder.minScore = in.readFloat();
   }
   if (in.readBoolean()) {
     builder.postQueryBuilder = in.readQuery();
   }
   if (in.readBoolean()) {
     builder.queryBuilder = in.readQuery();
   }
   if (in.readBoolean()) {
     int size = in.readVInt();
     List<BytesReference> rescoreBuilders = new ArrayList<>();
     for (int i = 0; i < size; i++) {
       rescoreBuilders.add(in.readBytesReference());
     }
     builder.rescoreBuilders = rescoreBuilders;
   }
   if (in.readBoolean()) {
     int size = in.readVInt();
     List<ScriptField> scriptFields = new ArrayList<>(size);
     for (int i = 0; i < size; i++) {
       scriptFields.add(ScriptField.PROTOTYPE.readFrom(in));
     }
     builder.scriptFields = scriptFields;
   }
   builder.size = in.readVInt();
   if (in.readBoolean()) {
     int size = in.readVInt();
     List<BytesReference> sorts = new ArrayList<>();
     for (int i = 0; i < size; i++) {
       sorts.add(in.readBytesReference());
     }
     builder.sorts = sorts;
   }
   if (in.readBoolean()) {
     int size = in.readVInt();
     List<String> stats = new ArrayList<>();
     for (int i = 0; i < size; i++) {
       stats.add(in.readString());
     }
     builder.stats = stats;
   }
   if (in.readBoolean()) {
     builder.suggestBuilder = in.readBytesReference();
   }
   builder.terminateAfter = in.readVInt();
   builder.timeoutInMillis = in.readLong();
   builder.trackScores = in.readBoolean();
   builder.version = in.readOptionalBoolean();
   if (in.readBoolean()) {
     builder.ext = in.readBytesReference();
   }
   return builder;
 }