@Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeString(STREAM.getName());
   out.writeOptionalString(scriptLang);
   out.writeString(scriptString);
   ScriptService.ScriptType.writeTo(scriptType, out);
   out.writeMap(params);
 }
 @Override
 public void toXContent(XContentBuilder builder) throws IOException {
   builder.startObject(STREAM.getName());
   if (script != null) {
     builder.field("script", script);
   }
   if (lang != null) {
     builder.field("lang", lang);
   }
   if (params != null) {
     builder.field("params", params);
   }
   if (scriptId != null) {
     builder.field("script_id", scriptId);
   }
   if (scriptFile != null) {
     builder.field("script_file", scriptFile);
   }
   builder.endObject();
 }