public class StoredScriptSource extends AbstractDiffable<StoredScriptSource> implements Writeable, ToXContentObject
StoredScriptSource
represents user-defined parameters for a script
saved in the ClusterState
.Writeable.Reader<V>, Writeable.Writer<V>
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Modifier and Type | Field and Description |
---|---|
static ParseField |
LANG_PARSE_FIELD
Standard
ParseField for lang on the inner level. |
static ParseField |
OPTIONS_PARSE_FIELD
Standard
ParseField for options on the inner level. |
static ParseField |
SCRIPT_PARSE_FIELD
Standard
ParseField for outer level of stored script source. |
static ParseField |
SOURCE_PARSE_FIELD
Standard
ParseField for source on the inner level. |
static ParseField |
TEMPLATE_PARSE_FIELD
Standard
ParseField for outer level of stored script source. |
EMPTY_PARAMS
Constructor and Description |
---|
StoredScriptSource(StreamInput in)
Reads a
StoredScriptSource from a stream. |
StoredScriptSource(java.lang.String source)
Constructor for use with
GetStoredScriptResponse
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
static StoredScriptSource |
fromXContent(XContentParser parser)
This will parse XContent into a
StoredScriptSource . |
java.lang.String |
getLang() |
java.util.Map<java.lang.String,java.lang.String> |
getOptions() |
java.lang.String |
getSource() |
int |
hashCode() |
static StoredScriptSource |
parse(java.lang.String lang,
BytesReference content,
XContentType xContentType)
This will parse XContent into a
StoredScriptSource . |
static Diff<StoredScriptSource> |
readDiffFrom(StreamInput in)
Required for
ScriptMetaData.ScriptMetadataDiff . |
java.lang.String |
toString() |
XContentBuilder |
toXContent(XContentBuilder builder,
ToXContent.Params params)
This will write XContent from a
StoredScriptSource . |
void |
writeTo(StreamOutput out)
Writes a
StoredScriptSource to a stream. |
diff, get, readDiffFrom
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isFragment
public static final ParseField SCRIPT_PARSE_FIELD
ParseField
for outer level of stored script source.public static final ParseField TEMPLATE_PARSE_FIELD
ParseField
for outer level of stored script source.public static final ParseField LANG_PARSE_FIELD
ParseField
for lang on the inner level.public static final ParseField SOURCE_PARSE_FIELD
ParseField
for source on the inner level.public static final ParseField OPTIONS_PARSE_FIELD
ParseField
for options on the inner level.public StoredScriptSource(java.lang.String source)
GetStoredScriptResponse
to support the deprecated stored script namespace.public StoredScriptSource(java.lang.String lang, java.lang.String source, java.util.Map<java.lang.String,java.lang.String> options)
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.public StoredScriptSource(StreamInput in) throws java.io.IOException
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.java.io.IOException
public static StoredScriptSource parse(java.lang.String lang, BytesReference content, XContentType xContentType)
StoredScriptSource
. 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). See ScriptMetaData
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.lang
- An optional parameter to allow for use of the deprecated stored
script namespace. This will be used to specify the language
coming in as a url parameter from a request or for stored templates.content
- The content from the request to be parsed as described above.StoredScriptSource
.public static StoredScriptSource fromXContent(XContentParser parser) throws java.io.IOException
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.java.io.IOException
public static Diff<StoredScriptSource> readDiffFrom(StreamInput in) throws java.io.IOException
ScriptMetaData.ScriptMetadataDiff
. Uses
the StoredScriptSource(StreamInput)
constructor.java.io.IOException
public void writeTo(StreamOutput out) throws java.io.IOException
StoredScriptSource
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.public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
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.toXContent
in interface ToXContent
java.io.IOException
public java.lang.String getLang()
public java.lang.String getSource()
public java.util.Map<java.lang.String,java.lang.String> getOptions()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object