Package org.elasticsearch.script
Class StoredScriptSource
- java.lang.Object
-
- org.elasticsearch.cluster.AbstractDiffable<StoredScriptSource>
-
- org.elasticsearch.script.StoredScriptSource
-
- All Implemented Interfaces:
Diffable<StoredScriptSource>
,Writeable
,ToXContent
,ToXContentObject
public class StoredScriptSource extends AbstractDiffable<StoredScriptSource> implements Writeable, ToXContentObject
StoredScriptSource
represents user-defined parameters for a script saved in theClusterState
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static ParseField
LANG_PARSE_FIELD
StandardParseField
for lang on the inner level.static ParseField
OPTIONS_PARSE_FIELD
StandardParseField
for options on the inner level.static ParseField
SCRIPT_PARSE_FIELD
StandardParseField
for outer level of stored script source.static ParseField
SOURCE_PARSE_FIELD
StandardParseField
for source on the inner level.static ParseField
TEMPLATE_NO_WRAPPER_PARSE_FIELD
StandardParseField
for query on the inner field.static ParseField
TEMPLATE_PARSE_FIELD
StandardParseField
for outer level of stored script source.-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description StoredScriptSource(java.lang.String source)
Constructor for use withGetStoredScriptResponse
to support the deprecated stored script namespace.StoredScriptSource(java.lang.String lang, java.lang.String source, java.util.Map<java.lang.String,java.lang.String> options)
Standard StoredScriptSource constructor.StoredScriptSource(StreamInput in)
Reads aStoredScriptSource
from a stream.
-
Method Summary
Modifier and Type Method Description boolean
equals(java.lang.Object o)
static StoredScriptSource
fromXContent(XContentParser parser, boolean ignoreEmpty)
This will parse XContent into aStoredScriptSource
.java.lang.String
getLang()
java.util.Map<java.lang.String,java.lang.String>
getOptions()
java.lang.String
getSource()
int
hashCode()
static StoredScriptSource
parse(BytesReference content, XContentType xContentType)
This will parse XContent into aStoredScriptSource
.static Diff<StoredScriptSource>
readDiffFrom(StreamInput in)
Required forScriptMetaData.ScriptMetadataDiff
.java.lang.String
toString()
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
This will write XContent from aStoredScriptSource
.void
writeTo(StreamOutput out)
Writes aStoredScriptSource
to a stream.-
Methods inherited from class org.elasticsearch.cluster.AbstractDiffable
diff, get, readDiffFrom
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
SCRIPT_PARSE_FIELD
public static final ParseField SCRIPT_PARSE_FIELD
StandardParseField
for outer level of stored script source.
-
TEMPLATE_PARSE_FIELD
public static final ParseField TEMPLATE_PARSE_FIELD
StandardParseField
for outer level of stored script source.
-
TEMPLATE_NO_WRAPPER_PARSE_FIELD
public static final ParseField TEMPLATE_NO_WRAPPER_PARSE_FIELD
StandardParseField
for query on the inner field.
-
LANG_PARSE_FIELD
public static final ParseField LANG_PARSE_FIELD
StandardParseField
for lang on the inner level.
-
SOURCE_PARSE_FIELD
public static final ParseField SOURCE_PARSE_FIELD
StandardParseField
for source on the inner level.
-
OPTIONS_PARSE_FIELD
public static final ParseField OPTIONS_PARSE_FIELD
StandardParseField
for options on the inner level.
-
-
Constructor Detail
-
StoredScriptSource
public StoredScriptSource(java.lang.String source)
Constructor for use withGetStoredScriptResponse
to support the deprecated stored script namespace.
-
StoredScriptSource
public StoredScriptSource(java.lang.String lang, java.lang.String source, java.util.Map<java.lang.String,java.lang.String> options)
Standard StoredScriptSource constructor.- Parameters:
lang
- The language to compile the script with. Must not benull
.source
- The source source to compile with. Must not benull
.options
- Compiler options to be compiled with. Must not benull
, use an emptyMap
to represent no options.
-
StoredScriptSource
public StoredScriptSource(StreamInput in) throws java.io.IOException
Reads aStoredScriptSource
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:
java.io.IOException
-
-
Method Detail
-
parse
public static StoredScriptSource parse(BytesReference content, XContentType xContentType)
This will parse XContent into aStoredScriptSource
. The following formats can be parsed: The simple script format with no compiler options or user-defined params: Example:{"script": "return Math.log(doc.popularity) * 100;"}
The above format requires the lang to be specified using the deprecated stored script namespace (as a url parameter during a put request). SeeScriptMetaData
for more information about the stored script namespaces. The complex script format using the new stored script namespace where lang and source are required but options is optional:{ "script" : { "lang" : "<lang>", "source" : "<source>", "options" : { "option0" : "<option0>", "option1" : "<option1>", ... } } }
Example:{ "script": { "lang" : "painless", "source" : "return Math.log(doc.popularity) * params.multiplier" } }
The use of "source" may also be substituted with "code" for backcompat with 5.3 to 5.5 format. For example:{ "script" : { "lang" : "<lang>", "code" : "<source>", "options" : { "option0" : "<option0>", "option1" : "<option1>", ... } } }
The simple template format:{ "query" : ... }
The complex template format:{ "template": { "query" : ... } }
Note that templates can be handled as both strings and complex JSON objects. Also templates may be part of the 'source' parameter in a script. The Parser can handle this case as well.- Parameters:
content
- The content from the request to be parsed as described above.- Returns:
- The parsed
StoredScriptSource
.
-
fromXContent
public static StoredScriptSource fromXContent(XContentParser parser, boolean ignoreEmpty)
This will parse XContent into aStoredScriptSource
. 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 astrue
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 java.io.IOException
Required forScriptMetaData.ScriptMetadataDiff
. Uses theStoredScriptSource(StreamInput)
constructor.- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Writes aStoredScriptSource
to a stream. Version 5.3+ will write 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.
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
This will write XContent from aStoredScriptSource
. 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 interfaceToXContent
- Throws:
java.io.IOException
-
getLang
public java.lang.String getLang()
- Returns:
- The language used for compiling this script.
-
getSource
public java.lang.String getSource()
- Returns:
- The source used for compiling this script.
-
getOptions
public java.util.Map<java.lang.String,java.lang.String> getOptions()
- Returns:
- The compiler options used for this script.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-