Class StoredScriptSource
- All Implemented Interfaces:
Diffable<StoredScriptSource>
,org.opensearch.core.common.io.stream.Writeable
,org.opensearch.core.xcontent.ToXContent
,org.opensearch.core.xcontent.ToXContentObject
StoredScriptSource
represents user-defined parameters for a script
saved in the ClusterState
.- Opensearch.api:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opensearch.core.xcontent.ToXContent
org.opensearch.core.xcontent.ToXContent.DelegatingMapParams, org.opensearch.core.xcontent.ToXContent.MapParams, org.opensearch.core.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.opensearch.core.common.io.stream.Writeable
org.opensearch.core.common.io.stream.Writeable.Reader<V>, org.opensearch.core.common.io.stream.Writeable.WriteableRegistry, org.opensearch.core.common.io.stream.Writeable.Writer<V>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.opensearch.core.ParseField
StandardParseField
for lang on the inner level.static final org.opensearch.core.ParseField
StandardParseField
for options on the inner level.static final org.opensearch.core.ParseField
StandardParseField
for outer level of stored script source.static final org.opensearch.core.ParseField
StandardParseField
for source on the inner level.Fields inherited from interface org.opensearch.core.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
ConstructorDescriptionStandard StoredScriptSource constructor.StoredScriptSource
(org.opensearch.core.common.io.stream.StreamInput in) Reads aStoredScriptSource
from a stream. -
Method Summary
Modifier and TypeMethodDescriptionboolean
static StoredScriptSource
fromXContent
(org.opensearch.core.xcontent.XContentParser parser, boolean ignoreEmpty) This will parse XContent into aStoredScriptSource
.getLang()
int
hashCode()
static StoredScriptSource
parse
(org.opensearch.core.common.bytes.BytesReference content, org.opensearch.core.xcontent.MediaType mediaType) This will parse XContent into aStoredScriptSource
.static Diff
<StoredScriptSource> readDiffFrom
(org.opensearch.core.common.io.stream.StreamInput in) Required forScriptMetadata.ScriptMetadataDiff
.toString()
org.opensearch.core.xcontent.XContentBuilder
toXContent
(org.opensearch.core.xcontent.XContentBuilder builder, org.opensearch.core.xcontent.ToXContent.Params params) This will write XContent from aStoredScriptSource
.void
writeTo
(org.opensearch.core.common.io.stream.StreamOutput out) Writes aStoredScriptSource
to a stream.Methods inherited from class org.opensearch.cluster.AbstractDiffable
diff, readDiffFrom
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opensearch.core.xcontent.ToXContentObject
isFragment
-
Field Details
-
SCRIPT_PARSE_FIELD
public static final org.opensearch.core.ParseField SCRIPT_PARSE_FIELDStandardParseField
for outer level of stored script source. -
LANG_PARSE_FIELD
public static final org.opensearch.core.ParseField LANG_PARSE_FIELDStandardParseField
for lang on the inner level. -
SOURCE_PARSE_FIELD
public static final org.opensearch.core.ParseField SOURCE_PARSE_FIELDStandardParseField
for source on the inner level. -
OPTIONS_PARSE_FIELD
public static final org.opensearch.core.ParseField OPTIONS_PARSE_FIELDStandardParseField
for options on the inner level.
-
-
Constructor Details
-
StoredScriptSource
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
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:
IOException
-
-
Method Details
-
parse
public static StoredScriptSource parse(org.opensearch.core.common.bytes.BytesReference content, org.opensearch.core.xcontent.MediaType mediaType) 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). 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>", ... } } }
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.mediaType
- The media type of the request- Returns:
- The parsed
StoredScriptSource
.
-
fromXContent
public static StoredScriptSource fromXContent(org.opensearch.core.xcontent.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(org.opensearch.core.common.io.stream.StreamInput in) throws IOException Required forScriptMetadata.ScriptMetadataDiff
. Uses theStoredScriptSource(StreamInput)
constructor.- Throws:
IOException
-
writeTo
Writes aStoredScriptSource
to a stream. Will write all of the lang, source, and options parameters.- Specified by:
writeTo
in interfaceorg.opensearch.core.common.io.stream.Writeable
- Throws:
IOException
-
toXContent
public org.opensearch.core.xcontent.XContentBuilder toXContent(org.opensearch.core.xcontent.XContentBuilder builder, org.opensearch.core.xcontent.ToXContent.Params params) throws 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 interfaceorg.opensearch.core.xcontent.ToXContent
- Throws:
IOException
-
getLang
- Returns:
- The language used for compiling this script.
-
getSource
- Returns:
- The source used for compiling this script.
-
getOptions
- Returns:
- The compiler options used for this script.
-
equals
-
hashCode
public int hashCode() -
toString
-