Class StoredScriptSource

java.lang.Object
org.elasticsearch.script.StoredScriptSource
All Implemented Interfaces:
Diffable<StoredScriptSource>, SimpleDiffable<StoredScriptSource>, Writeable, org.elasticsearch.xcontent.ToXContent, org.elasticsearch.xcontent.ToXContentObject

public class StoredScriptSource extends Object implements SimpleDiffable<StoredScriptSource>, Writeable, org.elasticsearch.xcontent.ToXContentObject
StoredScriptSource represents user-defined parameters for a script saved in the ClusterState.
  • Field Details

    • SCRIPT_PARSE_FIELD

      public static final org.elasticsearch.xcontent.ParseField SCRIPT_PARSE_FIELD
      Standard ParseField for outer level of stored script source.
    • LANG_PARSE_FIELD

      public static final org.elasticsearch.xcontent.ParseField LANG_PARSE_FIELD
      Standard ParseField for lang on the inner level.
    • SOURCE_PARSE_FIELD

      public static final org.elasticsearch.xcontent.ParseField SOURCE_PARSE_FIELD
      Standard ParseField for source on the inner level.
    • OPTIONS_PARSE_FIELD

      public static final org.elasticsearch.xcontent.ParseField OPTIONS_PARSE_FIELD
      Standard ParseField for options on the inner level.
  • Constructor Details

    • StoredScriptSource

      public StoredScriptSource(String lang, String source, Map<String,String> options)
      Standard StoredScriptSource constructor.
      Parameters:
      lang - The language to compile the script with. Must not be null.
      source - The source source to compile with. Must not be null.
      options - Compiler options to be compiled with. Must not be null, use an empty Map to represent no options.
    • StoredScriptSource

      public StoredScriptSource(StreamInput in) throws IOException
      Reads a StoredScriptSource from a stream. Version 5.3+ will read all of the lang, source, and options parameters. For versions prior to 5.3, only the source parameter will be read in as a bytes reference.
      Throws:
      IOException
  • Method Details

    • parse

      public static StoredScriptSource parse(BytesReference content, org.elasticsearch.xcontent.XContentType xContentType)
      This will parse XContent into a StoredScriptSource. Examples of legal JSON: { "script" : { "lang" : "<lang>", "source" : "<source>", "options" : { "option0" : "<option0>", "option1" : "<option1>", ... } } } Example: { "script": { "lang" : "painless", "source" : "return Math.log(doc.popularity) * params.multiplier" } } Note that the "source" parameter can also handle template parsing including from a complex JSON object.
      Parameters:
      content - The content from the request to be parsed as described above.
      Returns:
      The parsed StoredScriptSource.
    • fromXContent

      public static StoredScriptSource fromXContent(org.elasticsearch.xcontent.XContentParser parser, boolean ignoreEmpty)
      This will parse XContent into a StoredScriptSource. The following format is what will be parsed: { "script" : { "lang" : "<lang>", "source" : "<source>", "options" : { "option0" : "<option0>", "option1" : "<option1>", ... } } } Note that the "source" parameter can also handle template parsing including from a complex JSON object.
      Parameters:
      ignoreEmpty - Specify as true to ignoreEmpty the empty source check. This allows empty templates to be loaded for backwards compatibility.
    • readDiffFrom

      public static Diff<StoredScriptSource> readDiffFrom(StreamInput in) throws IOException
      Required for ScriptMetadata.ScriptMetadataDiff. Uses the StoredScriptSource(StreamInput) constructor.
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Writes a StoredScriptSource to a stream. Will write all of the lang, source, and options parameters.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • toXContent

      public org.elasticsearch.xcontent.XContentBuilder toXContent(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) throws IOException
      This will write XContent from a StoredScriptSource. The following format will be written: { "script" : { "lang" : "<lang>", "source" : "<source>", "options" : { "option0" : "<option0>", "option1" : "<option1>", ... } } } Note that the 'source' parameter can also handle templates written as complex JSON.
      Specified by:
      toXContent in interface org.elasticsearch.xcontent.ToXContent
      Throws:
      IOException
    • getLang

      public String getLang()
      Returns:
      The language used for compiling this script.
    • getSource

      public String getSource()
      Returns:
      The source used for compiling this script.
    • getOptions

      public Map<String,String> getOptions()
      Returns:
      The compiler options used for this script.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object