From 1d0d5ed66f5cdb70ca3cf8661b386e5a8cd359a6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 7 Jun 2017 15:37:36 -0700 Subject: [PATCH 1/9] Scripting: Change keys for inline/stored scripts to source/id This commit adds back "id" as the key within a script to specify a stored script (which with file scripts now gone is no longer ambiguous). It also adds "source" as a replacement for "code". This is in an attempt to normalize how scripts are specified across both put stored scripts and script usages, including search template requests. --- .../GetStoredScriptResponse.java | 2 +- .../cluster/RestGetStoredScriptAction.java | 4 +- .../java/org/elasticsearch/script/Script.java | 30 +++-- .../elasticsearch/script/ScriptMetaData.java | 2 +- .../elasticsearch/script/ScriptService.java | 4 +- .../org/elasticsearch/script/ScriptType.java | 7 +- .../script/StoredScriptSource.java | 107 +++++++++++------- .../action/update/UpdateRequestTests.java | 10 +- .../index/query/ScriptQueryBuilderTests.java | 2 +- .../script/ScriptMetaDataTests.java | 18 +-- .../script/ScriptServiceTests.java | 4 +- .../script/StoredScriptTests.java | 14 ++- .../elasticsearch/script/StoredScriptsIT.java | 2 +- .../search/sort/ScriptSortBuilderTests.java | 2 +- .../action/bulk/simple-bulk4.json | 2 +- .../test/lang_expression/20_search.yml | 2 +- .../mustache/RestGetSearchTemplateAction.java | 2 +- .../mustache/RestSearchTemplateAction.java | 2 +- .../mustache/MustacheScriptEngineTests.java | 4 +- .../rest-api-spec/test/painless/15_update.yml | 10 +- .../test/painless/20_scriptfield.yml | 16 +-- .../test/painless/25_script_upsert.yml | 8 +- .../rest-api-spec/test/painless/30_search.yml | 40 +++---- .../test/painless/50_script_doc_values.yml | 56 ++++----- .../painless/60_script_doc_values_binary.yml | 4 +- .../rest-api-spec/test/reindex/10_script.yml | 22 ++-- .../rest-api-spec/test/reindex/20_broken.yml | 2 +- .../test/reindex/40_search_failures.yml | 2 +- .../test/update_by_query/10_script.yml | 16 +-- .../test/update_by_query/20_broken.yml | 2 +- .../update_by_query/40_search_failure.yml | 2 +- 31 files changed, 223 insertions(+), 177 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptResponse.java index 2dc0ed870c025..d543ac67e1d91 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptResponse.java @@ -81,7 +81,7 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().onOrAfter(Version.V_5_3_0)) { source.writeTo(out); } else { - out.writeString(source.getCode()); + out.writeString(source.getSource()); } } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java index c0ea3c6ff8bdd..693f22c36cf71 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java @@ -98,7 +98,7 @@ public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuil if (lang == null) { builder.startObject(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName()); builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), source.getLang()); - builder.field(StoredScriptSource.CODE_PARSE_FIELD.getPreferredName(), source.getCode()); + builder.field(StoredScriptSource.CODE_PARSE_FIELD.getPreferredName(), source.getSource()); if (source.getOptions().isEmpty() == false) { builder.field(StoredScriptSource.OPTIONS_PARSE_FIELD.getPreferredName(), source.getOptions()); @@ -106,7 +106,7 @@ public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuil builder.endObject(); } else { - builder.field(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName(), source.getCode()); + builder.field(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName(), source.getSource()); } } diff --git a/core/src/main/java/org/elasticsearch/script/Script.java b/core/src/main/java/org/elasticsearch/script/Script.java index f9b67e31b9954..6f356b8a5e579 100644 --- a/core/src/main/java/org/elasticsearch/script/Script.java +++ b/core/src/main/java/org/elasticsearch/script/Script.java @@ -113,6 +113,11 @@ public final class Script implements ToXContentObject, Writeable { */ public static final ParseField SCRIPT_PARSE_FIELD = new ParseField("script"); + /** + * Standard {@link ParseField} for source on the inner level. + */ + public static final ParseField SOURCE_PARSE_FIELD = new ParseField("source"); + /** * Standard {@link ParseField} for lang on the inner level. */ @@ -299,7 +304,10 @@ public static Script parse(XContentParser parser) throws IOException { * * {@code * { - * "" : "", + * // Exactly one of "id" or "source" must be specified + * "id" : "", + * // OR + * "source": "", * "lang" : "", * "options" : { * "option0" : "", @@ -317,7 +325,7 @@ public static Script parse(XContentParser parser) throws IOException { * Example: * {@code * { - * "inline" : "return Math.log(doc.popularity) * params.multiplier", + * "source" : "return Math.log(doc.popularity) * params.multiplier", * "lang" : "painless", * "params" : { * "multiplier" : 100.0 @@ -330,7 +338,7 @@ public static Script parse(XContentParser parser) throws IOException { * * {@code * { - * "inline" : { "query" : ... }, + * "source" : { "query" : ... }, * "lang" : "", * "options" : { * "option0" : "", @@ -567,7 +575,7 @@ public void writeTo(StreamOutput out) throws IOException { * * {@code * { - * "" : "", + * "<(id, source)>" : "", * "lang" : "", * "options" : { * "option0" : "", @@ -585,7 +593,7 @@ public void writeTo(StreamOutput out) throws IOException { * Example: * {@code * { - * "inline" : "return Math.log(doc.popularity) * params.multiplier;", + * "source" : "return Math.log(doc.popularity) * params.multiplier;", * "lang" : "painless", * "params" : { * "multiplier" : 100.0 @@ -600,7 +608,7 @@ public void writeTo(StreamOutput out) throws IOException { * * {@code * { - * "inline" : { "query" : ... }, + * "source" : { "query" : ... }, * "lang" : "", * "options" : { * "option0" : "", @@ -621,10 +629,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params builderParams) String contentType = options == null ? null : options.get(CONTENT_TYPE_OPTION); - if (type == ScriptType.INLINE && contentType != null && builder.contentType().mediaType().equals(contentType)) { - builder.rawField(type.getParseField().getPreferredName(), new BytesArray(idOrCode)); + if (type == ScriptType.INLINE) { + if (contentType != null && builder.contentType().mediaType().equals(contentType)) { + builder.rawField(SOURCE_PARSE_FIELD.getPreferredName(), new BytesArray(idOrCode)); + } else { + builder.field(SOURCE_PARSE_FIELD.getPreferredName(), idOrCode); + } } else { - builder.field(type.getParseField().getPreferredName(), idOrCode); + builder.field("id", idOrCode); } if (lang != null) { diff --git a/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java b/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java index f69302ce0140b..63b5e2e46ab8d 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java @@ -336,7 +336,7 @@ public ScriptMetaData(StreamInput in) throws IOException { throw new IllegalArgumentException("illegal stored script id [" + id + "], does not contain lang"); } else { source = new StoredScriptSource(in); - source = new StoredScriptSource(id.substring(0, split), source.getCode(), Collections.emptyMap()); + source = new StoredScriptSource(id.substring(0, split), source.getSource(), Collections.emptyMap()); } // Version 5.3+ can just be parsed normally using StoredScriptSource. } else { diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index 557ad6ca7cb68..a64d13c43ca4c 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -256,7 +256,7 @@ public FactoryType compile(Script script, ScriptContext imp public static final ParseField LANG_PARSE_FIELD = new ParseField("lang"); /** - * Standard {@link ParseField} for code on the inner level. + * Standard {@link ParseField} for source on the inner level. + */ + public static final ParseField SOURCE_PARSE_FIELD = new ParseField("source"); + + /** + * Standard {@link ParseField} for source on the inner level. */ public static final ParseField CODE_PARSE_FIELD = new ParseField("code"); @@ -85,7 +90,7 @@ public class StoredScriptSource extends AbstractDiffable imp */ private static final class Builder { private String lang; - private String code; + private String source; private Map options; private Builder() { @@ -99,19 +104,19 @@ private void setLang(String lang) { /** * Since stored scripts can accept templates rather than just scripts, they must also be able - * to handle template parsing, hence the need for custom parsing code. Templates can + * to handle template parsing, hence the need for custom parsing source. Templates can * consist of either an {@link String} or a JSON object. If a JSON object is discovered * then the content type option must also be saved as a compiler option. */ - private void setCode(XContentParser parser) { + private void setSource(XContentParser parser) { try { if (parser.currentToken() == Token.START_OBJECT) { //this is really for search templates, that need to be converted to json format XContentBuilder builder = XContentFactory.jsonBuilder(); - code = builder.copyCurrentStructure(parser).string(); + source = builder.copyCurrentStructure(parser).string(); options.put(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()); } else { - code = parser.text(); + source = parser.text(); } } catch (IOException exception) { throw new UncheckedIOException(exception); @@ -136,17 +141,17 @@ private StoredScriptSource build() { throw new IllegalArgumentException("lang cannot be empty"); } - if (code == null) { - throw new IllegalArgumentException("must specify code for stored script"); - } else if (code.isEmpty()) { - throw new IllegalArgumentException("code cannot be empty"); + if (source == null) { + throw new IllegalArgumentException("must specify source for stored script"); + } else if (source.isEmpty()) { + throw new IllegalArgumentException("source cannot be empty"); } if (options.size() > 1 || options.size() == 1 && options.get(Script.CONTENT_TYPE_OPTION) == null) { throw new IllegalArgumentException("illegal compiler options [" + options + "] specified"); } - return new StoredScriptSource(lang, code, options); + return new StoredScriptSource(lang, source, options); } } @@ -155,7 +160,9 @@ private StoredScriptSource build() { static { // Defines the fields necessary to parse a Script as XContent using an ObjectParser. PARSER.declareString(Builder::setLang, LANG_PARSE_FIELD); - PARSER.declareField(Builder::setCode, parser -> parser, CODE_PARSE_FIELD, ValueType.OBJECT_OR_STRING); + PARSER.declareField(Builder::setSource, parser -> parser, SOURCE_PARSE_FIELD, ValueType.OBJECT_OR_STRING); + // accepting "code" here is for backcompat with version 5.3 to 5.5 + PARSER.declareField(Builder::setSource, parser -> parser, CODE_PARSE_FIELD, ValueType.OBJECT_OR_STRING); PARSER.declareField(Builder::setOptions, XContentParser::mapStrings, OPTIONS_PARSE_FIELD, ValueType.OBJECT); } @@ -174,13 +181,13 @@ private StoredScriptSource build() { * the stored script namespaces. * * The complex script format using the new stored script namespace - * where lang and code are required but options is optional: + * where lang and source are required but options is optional: * * {@code * { * "script" : { * "lang" : "", - * "code" : "", + * "source" : "", * "options" : { * "option0" : "", * "option1" : "", @@ -195,7 +202,23 @@ private StoredScriptSource build() { * { * "script": { * "lang" : "painless", - * "code" : "return Math.log(doc.popularity) * params.multiplier" + * "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: + * + * {@code + * { + * "script" : { + * "lang" : "", + * "code" : "", + * "options" : { + * "option0" : "", + * "option1" : "", + * ... + * } * } * } * } @@ -219,7 +242,7 @@ private StoredScriptSource build() { * } * * Note that templates can be handled as both strings and complex JSON objects. - * Also templates may be part of the 'code' parameter in a script. The Parser + * Also templates may be part of the 'source' parameter in a script. The Parser * can handle this case as well. * * @param lang An optional parameter to allow for use of the deprecated stored @@ -267,7 +290,7 @@ public static StoredScriptSource parse(String lang, BytesReference content, XCon } } else { - throw new ParsingException(parser.getTokenLocation(), "unexpected token [" + token + "], expected [{, ]"); + throw new ParsingException(parser.getTokenLocation(), "unexpected token [" + token + "], expected [{, ]"); } } else { if (lang == null) { @@ -306,7 +329,7 @@ public static StoredScriptSource parse(String lang, BytesReference content, XCon * { * "script" : { * "lang" : "", - * "code" : "", + * "source" : "", * "options" : { * "option0" : "", * "option1" : "", @@ -316,7 +339,7 @@ public static StoredScriptSource parse(String lang, BytesReference content, XCon * } * } * - * Note that the "code" parameter can also handle template parsing including from + * Note that the "source" parameter can also handle template parsing including from * a complex JSON object. */ public static StoredScriptSource fromXContent(XContentParser parser) throws IOException { @@ -333,66 +356,66 @@ public static Diff readDiffFrom(StreamInput in) throws IOExc } private final String lang; - private final String code; + private final String source; private final Map options; /** * Constructor for use with {@link GetStoredScriptResponse} * to support the deprecated stored script namespace. */ - public StoredScriptSource(String code) { + public StoredScriptSource(String source) { this.lang = null; - this.code = Objects.requireNonNull(code); + this.source = Objects.requireNonNull(source); this.options = null; } /** * Standard StoredScriptSource constructor. * @param lang The language to compile the script with. Must not be {@code null}. - * @param code The source code to compile with. Must not be {@code null}. + * @param source The source source to compile with. Must not be {@code null}. * @param options Compiler options to be compiled with. Must not be {@code null}, * use an empty {@link Map} to represent no options. */ - public StoredScriptSource(String lang, String code, Map options) { + public StoredScriptSource(String lang, String source, Map options) { this.lang = Objects.requireNonNull(lang); - this.code = Objects.requireNonNull(code); + this.source = Objects.requireNonNull(source); this.options = Collections.unmodifiableMap(Objects.requireNonNull(options)); } /** * Reads a {@link StoredScriptSource} from a stream. Version 5.3+ will read - * all of the lang, code, and options parameters. For versions prior to 5.3, - * only the code parameter will be read in as a bytes reference. + * 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 StoredScriptSource(StreamInput in) throws IOException { if (in.getVersion().onOrAfter(Version.V_5_3_0)) { this.lang = in.readString(); - this.code = in.readString(); + this.source = in.readString(); @SuppressWarnings("unchecked") Map options = (Map)(Map)in.readMap(); this.options = options; } else { this.lang = null; - this.code = in.readBytesReference().utf8ToString(); + this.source = in.readBytesReference().utf8ToString(); this.options = null; } } /** * Writes a {@link StoredScriptSource} to a stream. Version 5.3+ will write - * all of the lang, code, and options parameters. For versions prior to 5.3, - * only the code parameter will be read in as a bytes reference. + * 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. */ @Override public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().onOrAfter(Version.V_5_3_0)) { out.writeString(lang); - out.writeString(code); + out.writeString(source); @SuppressWarnings("unchecked") Map options = (Map)(Map)this.options; out.writeMap(options); } else { - out.writeBytesReference(new BytesArray(code)); + out.writeBytesReference(new BytesArray(source)); } } @@ -403,7 +426,7 @@ public void writeTo(StreamOutput out) throws IOException { * { * "script" : { * "lang" : "", - * "code" : "", + * "source" : "", * "options" : { * "option0" : "", * "option1" : "", @@ -413,13 +436,13 @@ public void writeTo(StreamOutput out) throws IOException { * } * } * - * Note that the 'code' parameter can also handle templates written as complex JSON. + * Note that the 'source' parameter can also handle templates written as complex JSON. */ @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(LANG_PARSE_FIELD.getPreferredName(), lang); - builder.field(CODE_PARSE_FIELD.getPreferredName(), code); + builder.field(CODE_PARSE_FIELD.getPreferredName(), source); builder.field(OPTIONS_PARSE_FIELD.getPreferredName(), options); builder.endObject(); @@ -434,10 +457,10 @@ public String getLang() { } /** - * @return The code used for compiling this script. + * @return The source used for compiling this script. */ - public String getCode() { - return code; + public String getSource() { + return source; } /** @@ -455,7 +478,7 @@ public boolean equals(Object o) { StoredScriptSource that = (StoredScriptSource)o; if (lang != null ? !lang.equals(that.lang) : that.lang != null) return false; - if (code != null ? !code.equals(that.code) : that.code != null) return false; + if (source != null ? !source.equals(that.source) : that.source != null) return false; return options != null ? options.equals(that.options) : that.options == null; } @@ -463,7 +486,7 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = lang != null ? lang.hashCode() : 0; - result = 31 * result + (code != null ? code.hashCode() : 0); + result = 31 * result + (source != null ? source.hashCode() : 0); result = 31 * result + (options != null ? options.hashCode() : 0); return result; } @@ -472,7 +495,7 @@ public int hashCode() { public String toString() { return "StoredScriptSource{" + "lang='" + lang + '\'' + - ", code='" + code + '\'' + + ", source='" + source + '\'' + ", options=" + options + '}'; } diff --git a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java index e872d3d854ecc..8b389d69d382b 100644 --- a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java @@ -159,7 +159,7 @@ public void testFromXContent() throws Exception { // simple verbose script request.fromXContent(createParser(XContentFactory.jsonBuilder().startObject() - .startObject("script").field("inline", "script1").endObject() + .startObject("script").field("source", "script1").endObject() .endObject())); script = request.script(); assertThat(script, notNullValue()); @@ -173,7 +173,7 @@ public void testFromXContent() throws Exception { request = new UpdateRequest("test", "type", "1"); request.fromXContent(createParser(XContentFactory.jsonBuilder().startObject() .startObject("script") - .field("inline", "script1") + .field("source", "script1") .startObject("params") .field("param1", "value1") .endObject() @@ -195,7 +195,7 @@ public void testFromXContent() throws Exception { .startObject("params") .field("param1", "value1") .endObject() - .field("inline", "script1") + .field("source", "script1") .endObject() .endObject())); script = request.script(); @@ -215,7 +215,7 @@ public void testFromXContent() throws Exception { .startObject("params") .field("param1", "value1") .endObject() - .field("inline", "script1") + .field("source", "script1") .endObject() .startObject("upsert") .field("field1", "value1") @@ -249,7 +249,7 @@ public void testFromXContent() throws Exception { .startObject("params") .field("param1", "value1") .endObject() - .field("inline", "script1") + .field("source", "script1") .endObject().endObject())); script = request.script(); assertThat(script, notNullValue()); diff --git a/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java index 3be16e27c48cd..d273825f9794c 100644 --- a/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java @@ -66,7 +66,7 @@ public void testFromJsonVerbose() throws IOException { "{\n" + " \"script\" : {\n" + " \"script\" : {\n" + - " \"inline\" : \"5\",\n" + + " \"source\" : \"5\",\n" + " \"lang\" : \"mockscript\"\n" + " },\n" + " \"boost\" : 1.0,\n" + diff --git a/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java b/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java index fb1e0885a5f9a..f1315b9cdc49a 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java @@ -56,11 +56,11 @@ public void testGetScript() throws Exception { builder.storeScript("any", StoredScriptSource.parse("lang", sourceBuilder.bytes(), sourceBuilder.contentType())); ScriptMetaData scriptMetaData = builder.build(); - assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("template", "lang").getCode()); - assertEquals("value", scriptMetaData.getStoredScript("template_field", "lang").getCode()); - assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("script", "lang").getCode()); - assertEquals("value", scriptMetaData.getStoredScript("script_field", "lang").getCode()); - assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("any", "lang").getCode()); + assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("template", "lang").getSource()); + assertEquals("value", scriptMetaData.getStoredScript("template_field", "lang").getSource()); + assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("script", "lang").getSource()); + assertEquals("value", scriptMetaData.getStoredScript("script_field", "lang").getSource()); + assertEquals("{\"field\":\"value\"}", scriptMetaData.getStoredScript("any", "lang").getSource()); } public void testDiff() throws Exception { @@ -85,9 +85,9 @@ public void testDiff() throws Exception { assertNotNull(((DiffableUtils.MapDiff) diff.pipelines).getUpserts().get("4")); ScriptMetaData result = (ScriptMetaData) diff.apply(scriptMetaData1); - assertEquals("{\"foo\":\"abc\"}", result.getStoredScript("1", "lang").getCode()); - assertEquals("{\"foo\":\"changed\"}", result.getStoredScript("2", "lang").getCode()); - assertEquals("{\"foo\":\"jkl\"}", result.getStoredScript("4", "lang").getCode()); + assertEquals("{\"foo\":\"abc\"}", result.getStoredScript("1", "lang").getSource()); + assertEquals("{\"foo\":\"changed\"}", result.getStoredScript("2", "lang").getSource()); + assertEquals("{\"foo\":\"jkl\"}", result.getStoredScript("4", "lang").getSource()); } public void testBuilder() { @@ -95,7 +95,7 @@ public void testBuilder() { builder.storeScript("_id", StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"1 + 1\"}"), XContentType.JSON)); ScriptMetaData result = builder.build(); - assertEquals("1 + 1", result.getStoredScript("_id", "_lang").getCode()); + assertEquals("1 + 1", result.getStoredScript("_id", "_lang").getSource()); } private ScriptMetaData randomScriptMetaData(XContentType sourceContentType) throws IOException { diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index af1b0dc3d01c3..9a81b1bcbbde7 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -240,7 +240,7 @@ public void testStoreScript() throws Exception { ScriptMetaData scriptMetaData = ScriptMetaData.putStoredScript(null, "_id", StoredScriptSource.parse("_lang", script, XContentType.JSON)); assertNotNull(scriptMetaData); - assertEquals("abc", scriptMetaData.getStoredScript("_id", "_lang").getCode()); + assertEquals("abc", scriptMetaData.getStoredScript("_id", "_lang").getSource()); } public void testDeleteScript() throws Exception { @@ -266,7 +266,7 @@ public void testGetStoredScript() throws Exception { StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"), XContentType.JSON)).build())) .build(); - assertEquals("abc", scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id", "_lang")).getCode()); + assertEquals("abc", scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id", "_lang")).getSource()); assertNull(scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id2", "_lang"))); cs = ClusterState.builder(new ClusterName("_name")).build(); diff --git a/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java b/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java index af54afbf77dee..cad7013dce4ef 100644 --- a/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java @@ -248,6 +248,16 @@ public void testSourceParsing() throws Exception { } // complex script with script object + try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { + builder.startObject().field("script").startObject().field("lang", "lang").field("source", "code").endObject().endObject(); + + StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON); + StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); + + assertThat(parsed, equalTo(source)); + } + + // complex script using "code" backcompat try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code").endObject().endObject(); @@ -305,13 +315,13 @@ public void testSourceParsingErrors() throws Exception { assertThat(iae.getMessage(), equalTo("must specify lang for stored script")); } - // check for missing code parameter when parsing a script + // check for missing source parameter when parsing a script try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "lang").endObject().endObject(); IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON)); - assertThat(iae.getMessage(), equalTo("must specify code for stored script")); + assertThat(iae.getMessage(), equalTo("must specify source for stored script")); } // check for illegal options parameter when parsing a script diff --git a/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java b/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java index 63945cd03a681..80a8f4deaa741 100644 --- a/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java +++ b/core/src/test/java/org/elasticsearch/script/StoredScriptsIT.java @@ -55,7 +55,7 @@ public void testBasics() { .setId("foobar") .setContent(new BytesArray("{\"script\":\"1\"}"), XContentType.JSON)); String script = client().admin().cluster().prepareGetStoredScript(LANG, "foobar") - .get().getSource().getCode(); + .get().getSource().getSource(); assertNotNull(script); assertEquals("1", script); diff --git a/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java index 2ed8857f1220d..121085f34d79d 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java @@ -158,7 +158,7 @@ public void testParseJson() throws IOException { "\"_script\" : {\n" + "\"type\" : \"number\",\n" + "\"script\" : {\n" + - "\"inline\": \"doc['field_name'].value * factor\",\n" + + "\"source\": \"doc['field_name'].value * factor\",\n" + "\"params\" : {\n" + "\"factor\" : 1.1\n" + "}\n" + diff --git a/core/src/test/resources/org/elasticsearch/action/bulk/simple-bulk4.json b/core/src/test/resources/org/elasticsearch/action/bulk/simple-bulk4.json index 362e4a473e988..bbcc0dbd6868d 100644 --- a/core/src/test/resources/org/elasticsearch/action/bulk/simple-bulk4.json +++ b/core/src/test/resources/org/elasticsearch/action/bulk/simple-bulk4.json @@ -1,7 +1,7 @@ { "update" : {"_id" : "1", "_retry_on_conflict" : 2} } { "doc" : {"field" : "value"} } { "update" : { "_id" : "0", "_type" : "type1", "_index" : "index1" } } -{ "script" : { "inline" : "counter += param1", "lang" : "javascript", "params" : {"param1" : 1}}, "upsert" : {"counter" : 1}} +{ "script" : { "source" : "counter += param1", "lang" : "javascript", "params" : {"param1" : 1}}, "upsert" : {"counter" : 1}} { "delete" : { "_id" : "2" } } { "create" : { "_id" : "3" } } { "field1" : "value3" } diff --git a/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml b/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml index 36ff7f58ea69b..3f26d078bd0ba 100644 --- a/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml +++ b/modules/lang-expression/src/test/resources/rest-api-spec/test/lang_expression/20_search.yml @@ -22,6 +22,6 @@ setup: --- "Expressions scripting test": - - do: { search: { body: { script_fields : { my_field : { script: { lang: expression, inline: 'doc["age"].value + 19' } } } } } } + - do: { search: { body: { script_fields : { my_field : { script: { lang: expression, source: 'doc["age"].value + 19' } } } } } } - match: { hits.hits.0.fields.my_field.0: 42.0 } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java index d2b534e01f224..1fea2ca8cafad 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestGetSearchTemplateAction.java @@ -74,7 +74,7 @@ public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuil builder.field(FOUND_PARSE_FIELD.getPreferredName(), found); if (found) { - builder.field(StoredScriptSource.TEMPLATE_PARSE_FIELD.getPreferredName(), source.getCode()); + builder.field(StoredScriptSource.TEMPLATE_PARSE_FIELD.getPreferredName(), source.getSource()); } builder.endObject(); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index cb40b3f91f70b..6b7360f82fdaa 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -71,7 +71,7 @@ public class RestSearchTemplateAction extends BaseRestHandler { } else { request.setScript(parser.text()); } - }, new ParseField("inline", "template"), ObjectParser.ValueType.OBJECT_OR_STRING); + }, new ParseField("source", "inline", "template"), ObjectParser.ValueType.OBJECT_OR_STRING); } public RestSearchTemplateAction(Settings settings, RestController controller) { diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java index 0890b9b3c8cb9..b3509046241ed 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java @@ -76,7 +76,7 @@ public void testSimpleParameterReplace() { public void testSimple() throws IOException { String templateString = "{" - + "\"inline\":{\"match_{{template}}\": {}}," + + "\"source\":{\"match_{{template}}\": {}}," + "\"params\":{\"template\":\"all\"}" + "}"; XContentParser parser = createParser(JsonXContent.jsonXContent, templateString); @@ -89,7 +89,7 @@ public void testSimple() throws IOException { public void testParseTemplateAsSingleStringWithConditionalClause() throws IOException { String templateString = "{" - + " \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + " \"params\":{" + + " \"source\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + " \"params\":{" + " \"template\":\"all\"," + " \"use_it\": true" + " }" diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml index 9da3761d1b176..a64ad904c4963 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml @@ -18,7 +18,7 @@ body: script: lang: painless - inline: "ctx._source.foo = params.bar" + source: "ctx._source.foo = params.bar" params: { bar: 'xxx' } - match: { _index: test_1 } @@ -43,7 +43,7 @@ body: script: lang: painless - inline: "ctx._source.foo = 'yyy'" + source: "ctx._source.foo = 'yyy'" - match: { _index: test_1 } - match: { _type: test } @@ -67,7 +67,7 @@ body: script: lang: painless - inline: "ctx._source.missing_length = ctx._source.missing?.length()" + source: "ctx._source.missing_length = ctx._source.missing?.length()" - match: { _index: test_1 } - match: { _type: test } @@ -93,7 +93,7 @@ body: script: lang: painless - inline: "ctx._source.foo_length = ctx._source.foo?.length()" + source: "ctx._source.foo_length = ctx._source.foo?.length()" - match: { _index: test_1 } - match: { _type: test } @@ -132,7 +132,7 @@ body: script: lang: painless - inline: "for (def key : params.keySet()) { ctx._source[key] = params[key]}" + source: "for (def key : params.keySet()) { ctx._source[key] = params[key]}" params: { bar: 'xxx' } - match: { error.root_cause.0.type: "remote_transport_exception" } diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/20_scriptfield.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/20_scriptfield.yml index 3ebc8eeb579bc..e498a1737576e 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/20_scriptfield.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/20_scriptfield.yml @@ -39,7 +39,7 @@ setup: script_fields: bar: script: - inline: "doc['foo'].value + params.x;" + source: "doc['foo'].value + params.x;" params: x: "bbb" @@ -53,7 +53,7 @@ setup: script_fields: bar: script: - inline: "boolean compare(Supplier s, def v) {return s.get() == v;} + source: "boolean compare(Supplier s, def v) {return s.get() == v;} compare(() -> { return doc['foo'].value }, params.x);" params: x: "aaa" @@ -65,7 +65,7 @@ setup: script_fields: bar: script: - inline: "boolean compare(Supplier s, def v) {return s.get() == v;} + source: "boolean compare(Supplier s, def v) {return s.get() == v;} compare(() -> { return doc['foo'].value }, params.x);" params: x: "bbb" @@ -80,7 +80,7 @@ setup: script_fields: bar: script: - inline: "(doc['foo'].value?.length() ?: 0) + params.x;" + source: "(doc['foo'].value?.length() ?: 0) + params.x;" params: x: 5 @@ -95,7 +95,7 @@ setup: script_fields: bar: script: - inline: "(doc['missing'].value?.length() ?: 0) + params.x;" + source: "(doc['missing'].value?.length() ?: 0) + params.x;" params: x: 5 @@ -109,7 +109,7 @@ setup: script_fields: bar: script: - inline: "doc.date.value.dayOfWeek" + source: "doc.date.value.dayOfWeek" - match: { hits.hits.0.fields.bar.0: 7} @@ -121,7 +121,7 @@ setup: script_fields: bar: script: - inline: > + source: > StringBuilder b = new StringBuilder(); for (def date : doc.dates) { b.append(" ").append(date.getDayOfWeek()); @@ -139,7 +139,7 @@ setup: script_fields: bar: script: - inline: "while (true) {}" + source: "while (true) {}" - match: { error.root_cause.0.type: "script_exception" } - match: { error.root_cause.0.reason: "compile error" } diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/25_script_upsert.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/25_script_upsert.yml index 3be567f2acbbb..9622e6f4d3168 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/25_script_upsert.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/25_script_upsert.yml @@ -8,7 +8,7 @@ id: 1 body: script: - inline: "ctx._source.foo = params.bar" + source: "ctx._source.foo = params.bar" lang: "painless" params: { bar: 'xxx' } upsert: { foo: baz } @@ -29,7 +29,7 @@ id: 1 body: script: - inline: "ctx._source.foo = params.bar" + source: "ctx._source.foo = params.bar" lang: "painless" params: { bar: 'xxx' } upsert: { foo: baz } @@ -49,7 +49,7 @@ id: 2 body: script: - inline: "ctx._source.foo = params.bar" + source: "ctx._source.foo = params.bar" lang: "painless" params: { bar: 'xxx' } upsert: { foo: baz } @@ -70,7 +70,7 @@ id: 3 body: script: - inline: "ctx._source.has_now = ctx._now > 0" + source: "ctx._source.has_now = ctx._now > 0" lang: "painless" upsert: { has_now: false } scripted_upsert: true diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/30_search.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/30_search.yml index d92c0e41e6c9a..28679cb223fd1 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/30_search.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/30_search.yml @@ -29,12 +29,12 @@ query: script: script: - inline: "doc['num1'].value > 1;" + source: "doc['num1'].value > 1;" lang: painless script_fields: sNum1: script: - inline: "doc['num1'].value;" + source: "doc['num1'].value;" lang: painless sort: num1: @@ -51,7 +51,7 @@ query: script: script: - inline: "doc['num1'].value > params.param1;" + source: "doc['num1'].value > params.param1;" lang: painless params: param1: 1 @@ -59,7 +59,7 @@ script_fields: sNum1: script: - inline: "return doc['num1'].value;" + source: "return doc['num1'].value;" lang: painless sort: num1: @@ -76,7 +76,7 @@ query: script: script: - inline: "doc['num1'].value > params.param1;" + source: "doc['num1'].value > params.param1;" lang: painless params: param1: -1 @@ -84,7 +84,7 @@ script_fields: sNum1: script: - inline: "doc['num1'].value;" + source: "doc['num1'].value;" lang: painless sort: num1: @@ -102,7 +102,7 @@ query: script: script: - inline: "doc['bool'].value == false" + source: "doc['bool'].value == false" lang: painless - match: { hits.total: 1 } @@ -139,7 +139,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "doc['num1'].value" + "source": "doc['num1'].value" } } }] @@ -161,7 +161,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "-doc['num1'].value" + "source": "-doc['num1'].value" } } }] @@ -183,7 +183,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "Math.pow(doc['num1'].value, 2)" + "source": "Math.pow(doc['num1'].value, 2)" } } }] @@ -205,7 +205,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "Math.max(doc['num1'].value, 1)" + "source": "Math.max(doc['num1'].value, 1)" } } }] @@ -227,7 +227,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "doc['num1'].value * _score" + "source": "doc['num1'].value * _score" } } }] @@ -249,7 +249,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "params.param1 * params.param2 * _score", + "source": "params.param1 * params.param2 * _score", "params": { "param1": 2, "param2": 2 @@ -286,14 +286,14 @@ "script_score": { "script": { "lang": "painless", - "inline": "1" + "source": "1" } } }, { "script_score": { "script": { "lang": "painless", - "inline": "_score" + "source": "_score" } } } @@ -302,7 +302,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "_score" + "source": "_score" } } }] @@ -334,7 +334,7 @@ "script_score": { "script": { "lang": "painless", - "inline": "_score" + "source": "_score" } } }] @@ -343,7 +343,7 @@ terms: script: lang: painless - inline: "_score" + source: "_score" - match: { hits.total: 1 } - match: { hits.hits.0._score: 1.0 } @@ -370,7 +370,7 @@ script_fields: foobar: script: - inline: "doc['f'].values.size()" + source: "doc['f'].values.size()" lang: painless @@ -400,7 +400,7 @@ field: dummy_field script: lang: painless - inline: "_value + 1" + source: "_value + 1" - match: { hits.total: 1 } - match: { hits.hits.0._score: 1.0 } diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/50_script_doc_values.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/50_script_doc_values.yml index 3e80e5026dc0d..4e4b196838618 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/50_script_doc_values.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/50_script_doc_values.yml @@ -69,7 +69,7 @@ setup: script_fields: field: script: - inline: "doc['boolean'].get(0)" + source: "doc['boolean'].get(0)" - match: { hits.hits.0.fields.field.0: true } - do: @@ -78,7 +78,7 @@ setup: script_fields: field: script: - inline: "doc['boolean'].value" + source: "doc['boolean'].value" - match: { hits.hits.0.fields.field.0: true } --- @@ -89,7 +89,7 @@ setup: script_fields: field: script: - inline: "doc.date.get(0)" + source: "doc.date.get(0)" - match: { hits.hits.0.fields.field.0: '2017-01-01T12:11:12.000Z' } - do: @@ -98,7 +98,7 @@ setup: script_fields: field: script: - inline: "doc.date.value" + source: "doc.date.value" - match: { hits.hits.0.fields.field.0: '2017-01-01T12:11:12.000Z' } --- @@ -109,7 +109,7 @@ setup: script_fields: field: script: - inline: "doc['geo_point'].get(0)" + source: "doc['geo_point'].get(0)" - match: { hits.hits.0.fields.field.0.lat: 41.1199999647215 } - match: { hits.hits.0.fields.field.0.lon: -71.34000004269183 } @@ -119,7 +119,7 @@ setup: script_fields: field: script: - inline: "doc['geo_point'].value" + source: "doc['geo_point'].value" - match: { hits.hits.0.fields.field.0.lat: 41.1199999647215 } - match: { hits.hits.0.fields.field.0.lon: -71.34000004269183 } @@ -131,7 +131,7 @@ setup: script_fields: field: script: - inline: "doc['ip'].get(0)" + source: "doc['ip'].get(0)" - match: { hits.hits.0.fields.field.0: "192.168.0.1" } - do: @@ -140,7 +140,7 @@ setup: script_fields: field: script: - inline: "doc['ip'].value" + source: "doc['ip'].value" - match: { hits.hits.0.fields.field.0: "192.168.0.1" } --- @@ -151,7 +151,7 @@ setup: script_fields: field: script: - inline: "doc['keyword'].get(0)" + source: "doc['keyword'].get(0)" - match: { hits.hits.0.fields.field.0: "not split at all" } - do: @@ -160,7 +160,7 @@ setup: script_fields: field: script: - inline: "doc['keyword'].value" + source: "doc['keyword'].value" - match: { hits.hits.0.fields.field.0: "not split at all" } --- @@ -171,7 +171,7 @@ setup: script_fields: field: script: - inline: "doc['long'].get(0)" + source: "doc['long'].get(0)" - match: { hits.hits.0.fields.field.0: 12348732141234 } - do: @@ -180,7 +180,7 @@ setup: script_fields: field: script: - inline: "doc['long'].value" + source: "doc['long'].value" - match: { hits.hits.0.fields.field.0: 12348732141234 } --- @@ -191,7 +191,7 @@ setup: script_fields: field: script: - inline: "doc['integer'].get(0)" + source: "doc['integer'].get(0)" - match: { hits.hits.0.fields.field.0: 134134566 } - do: @@ -200,7 +200,7 @@ setup: script_fields: field: script: - inline: "doc['integer'].value" + source: "doc['integer'].value" - match: { hits.hits.0.fields.field.0: 134134566 } --- @@ -211,7 +211,7 @@ setup: script_fields: field: script: - inline: "doc['short'].get(0)" + source: "doc['short'].get(0)" - match: { hits.hits.0.fields.field.0: 1324 } - do: @@ -220,7 +220,7 @@ setup: script_fields: field: script: - inline: "doc['short'].value" + source: "doc['short'].value" - match: { hits.hits.0.fields.field.0: 1324 } --- @@ -231,7 +231,7 @@ setup: script_fields: field: script: - inline: "doc['byte'].get(0)" + source: "doc['byte'].get(0)" - match: { hits.hits.0.fields.field.0: 12 } - do: @@ -240,7 +240,7 @@ setup: script_fields: field: script: - inline: "doc['byte'].value" + source: "doc['byte'].value" - match: { hits.hits.0.fields.field.0: 12 } --- @@ -251,7 +251,7 @@ setup: script_fields: field: script: - inline: "doc['double'].get(0)" + source: "doc['double'].get(0)" - match: { hits.hits.0.fields.field.0: 3.14159265358979 } - do: @@ -260,7 +260,7 @@ setup: script_fields: field: script: - inline: "doc['double'].value" + source: "doc['double'].value" - match: { hits.hits.0.fields.field.0: 3.14159265358979 } --- @@ -271,7 +271,7 @@ setup: script_fields: field: script: - inline: "doc['float'].get(0)" + source: "doc['float'].get(0)" - match: { hits.hits.0.fields.field.0: 3.1415927410125732 } # this ends up as a double - do: @@ -280,7 +280,7 @@ setup: script_fields: field: script: - inline: "doc['float'].value" + source: "doc['float'].value" - match: { hits.hits.0.fields.field.0: 3.1415927410125732 } # this ends up as a double --- @@ -291,7 +291,7 @@ setup: script_fields: field: script: - inline: "doc['half_float'].get(0)" + source: "doc['half_float'].get(0)" - match: { hits.hits.0.fields.field.0: 3.140625 } - do: @@ -300,7 +300,7 @@ setup: script_fields: field: script: - inline: "doc['half_float'].value" + source: "doc['half_float'].value" - match: { hits.hits.0.fields.field.0: 3.140625 } --- @@ -311,7 +311,7 @@ setup: script_fields: field: script: - inline: "doc['scaled_float'].get(0)" + source: "doc['scaled_float'].get(0)" - match: { hits.hits.0.fields.field.0: 3.14 } - do: @@ -320,7 +320,7 @@ setup: script_fields: field: script: - inline: "doc['scaled_float'].value" + source: "doc['scaled_float'].value" - match: { hits.hits.0.fields.field.0: 3.14 } --- @@ -331,7 +331,7 @@ setup: script_fields: field: script: - inline: "doc['token_count'].get(0)" + source: "doc['token_count'].get(0)" - match: { hits.hits.0.fields.field.0: 5 } - do: @@ -340,5 +340,5 @@ setup: script_fields: field: script: - inline: "doc['token_count'].value" + source: "doc['token_count'].value" - match: { hits.hits.0.fields.field.0: 5 } diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/60_script_doc_values_binary.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/60_script_doc_values_binary.yml index 9a1188308082f..413c84f56c46b 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/60_script_doc_values_binary.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/60_script_doc_values_binary.yml @@ -33,7 +33,7 @@ script_fields: field: script: - inline: "doc['binary'].get(0).utf8ToString()" + source: "doc['binary'].get(0).utf8ToString()" - match: { hits.hits.0.fields.field.0: "Some binary blob" } - do: @@ -42,6 +42,6 @@ script_fields: field: script: - inline: "doc['binary'].value.utf8ToString()" + source: "doc['binary'].value.utf8ToString()" - match: { hits.hits.0.fields.field.0: "Some binary blob" } diff --git a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/10_script.yml b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/10_script.yml index 766e5ff3e7f4b..ba30ead52027d 100644 --- a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/10_script.yml +++ b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/10_script.yml @@ -19,7 +19,7 @@ index: new_twitter script: lang: painless - inline: ctx._source.user = "other" + ctx._source.user + source: ctx._source.user = "other" + ctx._source.user - match: {created: 1} - match: {noops: 0} @@ -59,7 +59,7 @@ index: new_twitter script: lang: painless - inline: if (ctx._id == "1") {ctx._source.user = "other" + ctx._source.user} + source: if (ctx._id == "1") {ctx._source.user = "other" + ctx._source.user} - match: {created: 2} - match: {noops: 0} @@ -118,7 +118,7 @@ index: new_twitter script: lang: painless - inline: ctx._parent = ctx._source.user + source: ctx._parent = ctx._source.user - match: {created: 1} - match: {noops: 0} @@ -162,7 +162,7 @@ index: new_twitter script: lang: painless - inline: ctx._routing = ctx._source.user + source: ctx._routing = ctx._source.user - match: {created: 2} - match: {noops: 0} @@ -220,7 +220,7 @@ index: new_twitter script: lang: painless - inline: ctx._parent = ctx._source.user; ctx._routing = "cat" + source: ctx._parent = ctx._source.user; ctx._routing = "cat" - match: {created: 1} - match: {noops: 0} @@ -266,7 +266,7 @@ index: new_twitter script: lang: painless - inline: if (ctx._source.user == "kimchy") {ctx._source.user = "not" + ctx._source.user} else {ctx.op = "noop"} + source: if (ctx._source.user == "kimchy") {ctx._source.user = "not" + ctx._source.user} else {ctx.op = "noop"} - match: {created: 1} - match: {noops: 1} @@ -319,7 +319,7 @@ index: new_twitter script: lang: painless - inline: ctx.op = "noop" + source: ctx.op = "noop" - match: {updated: 0} - match: {noops: 2} @@ -360,7 +360,7 @@ version_type: external script: lang: painless - inline: ctx._source.user = "other" + ctx._source.user; ctx._version = null + source: ctx._source.user = "other" + ctx._source.user; ctx._version = null - match: {updated: 1} - match: {noops: 0} @@ -400,7 +400,7 @@ index: new_twitter script: lang: painless - inline: ctx._source.user = "other" + ctx._source.user; ctx._id = null + source: ctx._source.user = "other" + ctx._source.user; ctx._id = null - match: {created: 1} - match: {noops: 0} @@ -440,7 +440,7 @@ index: new_twitter script: lang: painless - inline: if (ctx._source.user == "kimchy") {ctx._index = 'other_new_twitter'} + source: if (ctx._source.user == "kimchy") {ctx._index = 'other_new_twitter'} - match: {created: 2} - match: {noops: 0} @@ -513,7 +513,7 @@ type: type2 script: lang: painless - inline: "ctx._id = ctx._source.lang + '_' + ctx._source.id; + source: "ctx._id = ctx._source.lang + '_' + ctx._source.id; if (ctx._source.lang != \"en\" ) {ctx.op = 'delete'}" - match: {created: 1} - match: {noops: 0} diff --git a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/20_broken.yml b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/20_broken.yml index 5ec35b4c9dc71..fa2c0124ea2a0 100644 --- a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/20_broken.yml +++ b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/20_broken.yml @@ -20,5 +20,5 @@ index: new_twitter script: lang: painless - inline: syntax errors are fun! + source: syntax errors are fun! - match: {error.reason: 'compile error'} diff --git a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/40_search_failures.yml b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/40_search_failures.yml index a982609e3a1cc..9cf022f2de04a 100644 --- a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/40_search_failures.yml +++ b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/reindex/40_search_failures.yml @@ -19,7 +19,7 @@ script: script: lang: painless - inline: throw new IllegalArgumentException("Cats!") + source: throw new IllegalArgumentException("Cats!") dest: index: dest - match: {created: 0} diff --git a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/10_script.yml b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/10_script.yml index a4580b9733449..c4414229d7efa 100644 --- a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/10_script.yml +++ b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/10_script.yml @@ -16,7 +16,7 @@ body: script: lang: painless - inline: ctx._source.user = "not" + ctx._source.user + source: ctx._source.user = "not" + ctx._source.user - match: {updated: 1} - match: {noops: 0} @@ -53,7 +53,7 @@ body: script: lang: painless - inline: if (ctx._source.user == "kimchy") {ctx._source.user = "not" + ctx._source.user} else {ctx.op = "noop"} + source: if (ctx._source.user == "kimchy") {ctx._source.user = "not" + ctx._source.user} else {ctx.op = "noop"} - match: {updated: 1} - match: {noops: 1} @@ -99,7 +99,7 @@ body: script: lang: painless - inline: ctx.op = "noop" + source: ctx.op = "noop" - match: {updated: 0} - match: {noops: 2} - match: {batches: 1} @@ -122,7 +122,7 @@ body: script: lang: painless - inline: ctx.junk = "stuff" + source: ctx.junk = "stuff" --- "Can't change _id": @@ -142,7 +142,7 @@ body: script: lang: painless - inline: ctx._id = "stuff" + source: ctx._id = "stuff" --- "Update all docs with one doc deletion": @@ -180,7 +180,7 @@ body: script: lang: painless - inline: if (ctx._source.level != 11) {ctx._source.last_updated = "2016-01-02T00:00:00Z"} else {ctx.op = "delete"} + source: if (ctx._source.level != 11) {ctx._source.last_updated = "2016-01-02T00:00:00Z"} else {ctx.op = "delete"} - match: {updated: 3} - match: {deleted: 1} - match: {noops: 0} @@ -244,7 +244,7 @@ body: script: lang: painless - inline: | + source: | int choice = ctx._source.level % 3; if (choice == 0) { ctx._source.last_updated = "2016-01-02T00:00:00Z"; @@ -309,6 +309,6 @@ body: script: lang: painless - inline: if (ctx._source.user == "kimchy") {ctx.op = "update"} else {ctx.op = "junk"} + source: if (ctx._source.user == "kimchy") {ctx.op = "update"} else {ctx.op = "junk"} - match: { error.reason: 'Operation type [junk] not allowed, only [noop, index, delete] are allowed' } diff --git a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/20_broken.yml b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/20_broken.yml index aa497bff77e90..8863db5d2aef7 100644 --- a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/20_broken.yml +++ b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/20_broken.yml @@ -17,5 +17,5 @@ body: script: lang: painless - inline: syntax errors are fun! + source: syntax errors are fun! - match: {error.reason: 'compile error'} diff --git a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/40_search_failure.yml b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/40_search_failure.yml index 9960e2cd8ccaa..12801dd3e2ccc 100644 --- a/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/40_search_failure.yml +++ b/qa/smoke-test-reindex-with-all-modules/src/test/resources/rest-api-spec/test/update_by_query/40_search_failure.yml @@ -18,7 +18,7 @@ script: script: lang: painless - inline: throw new IllegalArgumentException("Cats!") + source: throw new IllegalArgumentException("Cats!") - match: {updated: 0} - match: {version_conflicts: 0} - match: {batches: 0} From 872602c66d033d86a6d559b2da06c8400453b454 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 09:46:54 -0700 Subject: [PATCH 2/9] fix mustache tests --- .../MultiSearchTemplateRequestTests.java | 3 +-- .../script/mustache/SearchTemplateIT.java | 6 ++--- .../mustache/SearchTemplateRequestTests.java | 8 +++---- .../mustache/simple-msearch-template.json | 6 ++--- .../20_render_search_template.yml | 12 +++++----- .../lang_mustache/25_custom_functions.yml | 4 ++-- .../test/lang_mustache/30_search_template.yml | 4 ++-- .../50_multi_search_template.yml | 22 +++++++++---------- .../test/lang_mustache/60_typed_keys.yml | 2 +- .../templates/file_query_template.mustache | 5 ----- .../templates/file_search_template.mustache | 12 ---------- .../resources/templates/template_1.mustache | 11 ---------- 12 files changed, 33 insertions(+), 62 deletions(-) delete mode 100644 modules/lang-mustache/src/test/resources/templates/file_query_template.mustache delete mode 100644 modules/lang-mustache/src/test/resources/templates/file_search_template.mustache delete mode 100644 modules/lang-mustache/src/test/resources/templates/template_1.mustache diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java index 13a02b0bc48f8..1ff5479623765 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.script.mustache; -import org.elasticsearch.action.search.MultiSearchRequest; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestRequest; @@ -74,7 +73,7 @@ public void testParseRequest() throws Exception { public void testParseWithCarriageReturn() throws Exception { final String content = "{\"index\":[\"test0\", \"test1\"], \"request_cache\": true}\r\n" + - "{\"inline\": {\"query\" : {\"match_{{template}}\" :{}}}, \"params\": {\"template\": \"all\" } }\r\n"; + "{\"source\": {\"query\" : {\"match_{{template}}\" :{}}}, \"params\": {\"template\": \"all\" } }\r\n"; RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray(content), XContentType.JSON).build(); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java index 4ac9263706e27..177688310302c 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java @@ -95,7 +95,7 @@ public void testTemplateQueryAsEscapedString() throws Exception { SearchRequest searchRequest = new SearchRequest(); searchRequest.indices("_all"); String query = - "{" + " \"inline\" : \"{ \\\"size\\\": \\\"{{size}}\\\", \\\"query\\\":{\\\"match_all\\\":{}}}\"," + "{" + " \"source\" : \"{ \\\"size\\\": \\\"{{size}}\\\", \\\"query\\\":{\\\"match_all\\\":{}}}\"," + " \"params\":{" + " \"size\": 1" + " }" @@ -115,7 +115,7 @@ public void testTemplateQueryAsEscapedStringStartingWithConditionalClause() thro searchRequest.indices("_all"); String templateString = "{" - + " \"inline\" : \"{ {{#use_size}} \\\"size\\\": \\\"{{size}}\\\", {{/use_size}} \\\"query\\\":{\\\"match_all\\\":{}}}\"," + + " \"source\" : \"{ {{#use_size}} \\\"size\\\": \\\"{{size}}\\\", {{/use_size}} \\\"query\\\":{\\\"match_all\\\":{}}}\"," + " \"params\":{" + " \"size\": 1," + " \"use_size\": true" @@ -136,7 +136,7 @@ public void testTemplateQueryAsEscapedStringWithConditionalClauseAtEnd() throws searchRequest.indices("_all"); String templateString = "{" - + " \"inline\" : \"{ \\\"query\\\":{\\\"match_all\\\":{}} {{#use_size}}, \\\"size\\\": \\\"{{size}}\\\" {{/use_size}} }\"," + + " \"source\" : \"{ \\\"query\\\":{\\\"match_all\\\":{}} {{#use_size}}, \\\"size\\\": \\\"{{size}}\\\" {{/use_size}} }\"," + " \"params\":{" + " \"size\": 1," + " \"use_size\": true" diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java index 25f46b9a79e83..51b7df3fc2cae 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java @@ -38,7 +38,7 @@ public class SearchTemplateRequestTests extends ESTestCase { public void testParseInlineTemplate() throws Exception { String source = "{" + - " 'inline' : {\n" + + " 'source' : {\n" + " 'query': {\n" + " 'terms': {\n" + " 'status': [\n" + @@ -59,7 +59,7 @@ public void testParseInlineTemplate() throws Exception { public void testParseInlineTemplateWithParams() throws Exception { String source = "{" + - " 'inline' : {" + + " 'source' : {" + " 'query': { 'match' : { '{{my_field}}' : '{{my_value}}' } }," + " 'size' : '{{my_size}}'" + " }," + @@ -80,7 +80,7 @@ public void testParseInlineTemplateWithParams() throws Exception { } public void testParseInlineTemplateAsString() throws Exception { - String source = "{'inline' : '{\\\"query\\\":{\\\"bool\\\":{\\\"must\\\":{\\\"match\\\":{\\\"foo\\\":\\\"{{text}}\\\"}}}}}'}"; + String source = "{'source' : '{\\\"query\\\":{\\\"bool\\\":{\\\"must\\\":{\\\"match\\\":{\\\"foo\\\":\\\"{{text}}\\\"}}}}}'}"; SearchTemplateRequest request = RestSearchTemplateAction.parse(newParser(source)); assertThat(request.getScript(), equalTo("{\"query\":{\"bool\":{\"must\":{\"match\":{\"foo\":\"{{text}}\"}}}}}")); @@ -90,7 +90,7 @@ public void testParseInlineTemplateAsString() throws Exception { @SuppressWarnings("unchecked") public void testParseInlineTemplateAsStringWithParams() throws Exception { - String source = "{'inline' : '{\\\"query\\\":{\\\"match\\\":{\\\"{{field}}\\\":\\\"{{value}}\\\"}}}', " + + String source = "{'source' : '{\\\"query\\\":{\\\"match\\\":{\\\"{{field}}\\\":\\\"{{value}}\\\"}}}', " + "'params': {'status': ['pending', 'published']}}"; SearchTemplateRequest request = RestSearchTemplateAction.parse(newParser(source)); diff --git a/modules/lang-mustache/src/test/resources/org/elasticsearch/script/mustache/simple-msearch-template.json b/modules/lang-mustache/src/test/resources/org/elasticsearch/script/mustache/simple-msearch-template.json index ac99bc299b335..11a0091492c4d 100644 --- a/modules/lang-mustache/src/test/resources/org/elasticsearch/script/mustache/simple-msearch-template.json +++ b/modules/lang-mustache/src/test/resources/org/elasticsearch/script/mustache/simple-msearch-template.json @@ -1,6 +1,6 @@ {"index":["test0", "test1"], "request_cache": true} -{"inline": {"query" : {"match_{{template}}" :{}}}, "params": {"template": "all" } } +{"source": {"query" : {"match_{{template}}" :{}}}, "params": {"template": "all" } } {"index" : "test2,test3", "type" : "type1", "preference": "_local"} -{"inline": {"query" : {"match_{{template}}" :{}}}, "params": {"template": "all" } } +{"source": {"query" : {"match_{{template}}" :{}}}, "params": {"template": "all" } } {"index" : ["test4", "test1"], "type" : [ "type2", "type1" ], "routing": "123"} -{"inline": {"query" : {"match_{{template}}" :{}}}, "params": {"template": "all" } } +{"source": {"query" : {"match_{{template}}" :{}}}, "params": {"template": "all" } } diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml index 130a79108d348..b631b9920ca14 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/20_render_search_template.yml @@ -34,14 +34,14 @@ - do: render_search_template: - body: { "inline": { "query": { "match": { "text": "{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } }, "params": { "my_value": "foo", "my_field": "field1" } } + body: { "source": { "query": { "match": { "text": "{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } }, "params": { "my_value": "foo", "my_field": "field1" } } - match: { template_output.query.match.text: "foo" } - match: { template_output.aggs.my_terms.terms.field: "field1" } - do: render_search_template: - body: { "inline": { "query": { "match": { "text": "{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } }, "params": { "my_value": "bar", "my_field": "my_other_field" } } + body: { "source": { "query": { "match": { "text": "{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } }, "params": { "my_value": "bar", "my_field": "my_other_field" } } - match: { template_output.query.match.text: "bar" } - match: { template_output.aggs.my_terms.terms.field: "my_other_field" } @@ -49,7 +49,7 @@ - do: catch: /Improperly.closed.variable.in.query-template/ render_search_template: - body: { "inline": { "query": { "match": { "text": "{{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } }, "params": { "my_value": "bar", "my_field": "field1" } } + body: { "source": { "query": { "match": { "text": "{{{my_value}}" } }, "aggs": { "my_terms": { "terms": { "field": "{{my_field}}" } } } }, "params": { "my_value": "bar", "my_field": "field1" } } --- "Escaped Stored Template validate tests": @@ -86,14 +86,14 @@ - do: render_search_template: - body: { "inline": "{ \"query\": { \"match\": { \"text\": \"{{my_value}}\" } }, \"size\": {{my_size}} }", "params": { "my_value": "foo", "my_size": 20 } } + body: { "source": "{ \"query\": { \"match\": { \"text\": \"{{my_value}}\" } }, \"size\": {{my_size}} }", "params": { "my_value": "foo", "my_size": 20 } } - match: { template_output.query.match.text: "foo" } - match: { template_output.size: 20 } - do: render_search_template: - body: { "inline": "{ \"query\": { \"match\": { \"text\": \"{{my_value}}\" } }, \"size\": {{my_size}} }", "params": { "my_value": "bar", "my_size": 100 } } + body: { "source": "{ \"query\": { \"match\": { \"text\": \"{{my_value}}\" } }, \"size\": {{my_size}} }", "params": { "my_value": "bar", "my_size": 100 } } - match: { template_output.query.match.text: "bar" } - match: { template_output.size: 100 } @@ -101,7 +101,7 @@ - do: catch: /Improperly.closed.variable.in.query-template/ render_search_template: - body: { "inline": "{ \"query\": { \"match\": { \"text\": \"{{{my_value}}\" } }, \"size\": {{my_size}} }", "params": { "my_value": "bar", "my_size": 100 } } + body: { "source": "{ \"query\": { \"match\": { \"text\": \"{{{my_value}}\" } }, \"size\": {{my_size}} }", "params": { "my_value": "bar", "my_size": 100 } } --- "Indexed Template query tests": diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/25_custom_functions.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/25_custom_functions.yml index a4e1dde463250..f58d40402b147 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/25_custom_functions.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/25_custom_functions.yml @@ -5,7 +5,7 @@ render_search_template: body: > { - "inline": { + "source": { "query": { "match": { "url": "https://localhost:9200/{{#url}}{{index}}{{/url}}/{{#url}}{{type}}{{/url}}/_search" @@ -27,7 +27,7 @@ render_search_template: body: > { - "inline": { + "source": { "query": { "match": { "url": "{{#url}}https://localhost:9200/{{#join}}indices{{/join}}/_stats{{/url}}" diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml index 40a16dc4f4a78..14b17b07a4d46 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/30_search_template.yml @@ -18,7 +18,7 @@ - do: search_template: - body: { "inline" : { "query": { "term": { "text": { "value": "{{template}}" } } } }, "params": { "template": "value1" } } + body: { "source" : { "query": { "term": { "text": { "value": "{{template}}" } } } }, "params": { "template": "value1" } } - match: { hits.total: 1 } @@ -35,7 +35,7 @@ - do: search_template: - body: { "inline" : { "query": { "match_{{template}}": {} } }, "params" : { "template" : "all" } } + body: { "source" : { "query": { "match_{{template}}": {} } }, "params" : { "template" : "all" } } - match: { hits.total: 2 } diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml index bc1b295c62c38..f179e0fc3a97f 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/50_multi_search_template.yml @@ -39,21 +39,21 @@ setup: msearch_template: body: - index: index_* - - inline: '{"query": {"match": {"foo": "{{value}}"} } }' + - source: '{"query": {"match": {"foo": "{{value}}"} } }' params: value: "foo" - index: index_* - - inline: '{"query": {"match": {"{{field}}": "{{value}}"} } }' + - source: '{"query": {"match": {"{{field}}": "{{value}}"} } }' params: field: "foo" value: "bar" - index: _all - - inline: '{"query": {"{{query_type}}": {{query_content}} } }' + - source: '{"query": {"{{query_type}}": {{query_content}} } }' params: query_type: "match_all" query_content: "{}" - index: _all - - inline: + - source: query: match: {foo: "{{text}}"} size: 0 @@ -75,25 +75,25 @@ setup: body: # Search 0 is OK - index: index_* - - inline: '{"query": {"match": {"foo": "{{value}}"} } }' + - source: '{"query": {"match": {"foo": "{{value}}"} } }' params: value: "foo" # Search 1 has an unclosed JSON template - index: index_* - - inline: '{"query": {"match": {' + - source: '{"query": {"match": {' params: field: "foo" value: "bar" # Search 2 is OK - index: _all - - inline: + - source: query: match: {foo: "{{text}}"} params: text: "baz" # Search 3 has an unknown query type - index: index_* - - inline: '{"query": {"{{query_type}}": {} }' # Unknown query type + - source: '{"query": {"{{query_type}}": {} }' # Unknown query type params: query_type: "unknown" @@ -113,15 +113,15 @@ setup: body: # Search 0 is OK - index: index_* - - inline: '{"query": {"match": {"foo": "{{value}}"} } }' + - source: '{"query": {"match": {"foo": "{{value}}"} } }' params: value: "foo" # Search 1 has not template - index: _all - - inline: "" + - source: "" # Search 2 is OK - index: index_* - - inline: '{"query": {"match": {"foo": "{{value}}"} } }' + - source: '{"query": {"match": {"foo": "{{value}}"} } }' params: value: "bar" diff --git a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml index c4adfbb106457..98adc5ab4c29b 100644 --- a/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml +++ b/modules/lang-mustache/src/test/resources/rest-api-spec/test/lang_mustache/60_typed_keys.yml @@ -102,7 +102,7 @@ setup: typed_keys: true body: - index: test-* - - inline: + - source: query: match: name: "{{name_value}}" diff --git a/modules/lang-mustache/src/test/resources/templates/file_query_template.mustache b/modules/lang-mustache/src/test/resources/templates/file_query_template.mustache deleted file mode 100644 index f083a1321335f..0000000000000 --- a/modules/lang-mustache/src/test/resources/templates/file_query_template.mustache +++ /dev/null @@ -1,5 +0,0 @@ -{ - "match": { - "text": "{{my_value}}" - } -} diff --git a/modules/lang-mustache/src/test/resources/templates/file_search_template.mustache b/modules/lang-mustache/src/test/resources/templates/file_search_template.mustache deleted file mode 100644 index beaf32ac0f185..0000000000000 --- a/modules/lang-mustache/src/test/resources/templates/file_search_template.mustache +++ /dev/null @@ -1,12 +0,0 @@ -{ - "query": { - "match": { - "text": "{{my_value}}" - } - }, - "aggs": { - "my_terms": { - "terms": { "field": "{{my_field}}" } - } - } -} diff --git a/modules/lang-mustache/src/test/resources/templates/template_1.mustache b/modules/lang-mustache/src/test/resources/templates/template_1.mustache deleted file mode 100644 index 29174be2ff052..0000000000000 --- a/modules/lang-mustache/src/test/resources/templates/template_1.mustache +++ /dev/null @@ -1,11 +0,0 @@ -{ - "query": { - "match": { - "{{field}}": { - "query" : "{{value}}", - "operator" : "{{operator}}{{^operator}}or{{/operator}}" - } - } - }, - "size": {{size}} -} From 18fd0e606ad5523bfbf6d2174217385a8f85e192 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 10:06:29 -0700 Subject: [PATCH 3/9] fix ingest --- docs/reference/docs/update.asciidoc | 2 +- .../ingest/common/ScriptProcessor.java | 26 ++++++++++++++----- .../common/ScriptProcessorFactoryTests.java | 22 +++++++++++----- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/docs/reference/docs/update.asciidoc b/docs/reference/docs/update.asciidoc index 47711830df62e..efa9fa0017715 100644 --- a/docs/reference/docs/update.asciidoc +++ b/docs/reference/docs/update.asciidoc @@ -243,7 +243,7 @@ POST sessions/session/dh3sgudg8gsrgl/_update } -------------------------------------------------- // CONSOLE -// TEST[s/"id": "my_web_session_summariser"/"inline": "ctx._source.page_view_event = params.pageViewEvent"/] +// TEST[s/"id": "my_web_session_summariser"/"source": "ctx._source.page_view_event = params.pageViewEvent"/] // TEST[continued] [float] diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java index 4200bbbebc169..55e12e382c650 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java @@ -19,7 +19,10 @@ package org.elasticsearch.ingest.common; +import org.apache.logging.log4j.Logger; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.ingest.AbstractProcessor; import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.Processor; @@ -84,6 +87,8 @@ Script getScript() { } public static final class Factory implements Processor.Factory { + private final Logger logger = ESLoggerFactory.getLogger(Factory.class); + private final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); private final ScriptService scriptService; @@ -96,18 +101,25 @@ public Factory(ScriptService scriptService) { public ScriptProcessor create(Map registry, String processorTag, Map config) throws Exception { String lang = readOptionalStringProperty(TYPE, processorTag, config, "lang"); - String inline = readOptionalStringProperty(TYPE, processorTag, config, "inline"); + String source = readOptionalStringProperty(TYPE, processorTag, config, "source"); String id = readOptionalStringProperty(TYPE, processorTag, config, "id"); Map params = readOptionalMap(TYPE, processorTag, config, "params"); - boolean containsNoScript = !hasLength(id) && !hasLength(inline); + if (source == null) { + source = readOptionalStringProperty(TYPE, processorTag, config, "inline"); + if (source != null) { + deprecationLogger.deprecated("Specifying script source with [inline] is deprecated, use [source] instead."); + } + } + + boolean containsNoScript = !hasLength(id) && !hasLength(source); if (containsNoScript) { - throw newConfigurationException(TYPE, processorTag, null, "Need [id] or [inline] parameter to refer to scripts"); + throw newConfigurationException(TYPE, processorTag, null, "Need [id] or [source] parameter to refer to scripts"); } - boolean moreThanOneConfigured = Strings.hasLength(id) && Strings.hasLength(inline); + boolean moreThanOneConfigured = Strings.hasLength(id) && Strings.hasLength(source); if (moreThanOneConfigured) { - throw newConfigurationException(TYPE, processorTag, null, "Only one of [id] or [inline] may be configured"); + throw newConfigurationException(TYPE, processorTag, null, "Only one of [id] or [source] may be configured"); } if (lang == null) { @@ -120,8 +132,8 @@ public ScriptProcessor create(Map registry, String pr final Script script; String scriptPropertyUsed; - if (Strings.hasLength(inline)) { - script = new Script(INLINE, lang, inline, (Map)params); + if (Strings.hasLength(source)) { + script = new Script(INLINE, lang, source, (Map)params); scriptPropertyUsed = "inline"; } else if (Strings.hasLength(id)) { script = new Script(STORED, lang, id, (Map)params); diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java index 1610b9bf01cd1..485c7c43609c6 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java @@ -43,7 +43,7 @@ public class ScriptProcessorFactoryTests extends ESTestCase { static { Map map = new HashMap<>(); map.put("id", "stored"); - map.put("inline", "inline"); + map.put("source", "inline"); ingestScriptParamToType = Collections.unmodifiableMap(map); } @@ -54,7 +54,7 @@ public void init() { public void testFactoryValidationWithDefaultLang() throws Exception { Map configMap = new HashMap<>(); - String randomType = randomFrom("id", "inline"); + String randomType = randomFrom("id", "source"); configMap.put(randomType, "foo"); ScriptProcessor processor = factory.create(null, randomAlphaOfLength(10), configMap); assertThat(processor.getScript().getLang(), equalTo(Script.DEFAULT_SCRIPT_LANG)); @@ -64,7 +64,7 @@ public void testFactoryValidationWithDefaultLang() throws Exception { public void testFactoryValidationWithParams() throws Exception { Map configMap = new HashMap<>(); - String randomType = randomFrom("id", "inline"); + String randomType = randomFrom("id", "source"); Map randomParams = Collections.singletonMap(randomAlphaOfLength(10), randomAlphaOfLength(10)); configMap.put(randomType, "foo"); configMap.put("params", randomParams); @@ -77,12 +77,12 @@ public void testFactoryValidationWithParams() throws Exception { public void testFactoryValidationForMultipleScriptingTypes() throws Exception { Map configMap = new HashMap<>(); configMap.put("id", "foo"); - configMap.put("inline", "bar"); + configMap.put("source", "bar"); configMap.put("lang", "mockscript"); ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, randomAlphaOfLength(10), configMap)); - assertThat(exception.getMessage(), is("Only one of [id] or [inline] may be configured")); + assertThat(exception.getMessage(), is("Only one of [id] or [source] may be configured")); } public void testFactoryValidationAtLeastOneScriptingType() throws Exception { @@ -92,11 +92,19 @@ public void testFactoryValidationAtLeastOneScriptingType() throws Exception { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> factory.create(null, randomAlphaOfLength(10), configMap)); - assertThat(exception.getMessage(), is("Need [id] or [inline] parameter to refer to scripts")); + assertThat(exception.getMessage(), is("Need [id] or [source] parameter to refer to scripts")); + } + + public void testInlineBackcompat() throws Exception { + Map configMap = new HashMap<>(); + configMap.put("inline", "code"); + + factory.create(null, randomAlphaOfLength(10), configMap); + assertWarnings("Specifying script source with [inline] is deprecated, use [source] instead."); } public void testFactoryInvalidateWithInvalidCompiledScript() throws Exception { - String randomType = randomFrom("inline", "id"); + String randomType = randomFrom("source", "id"); ScriptService mockedScriptService = mock(ScriptService.class); ScriptException thrownException = new ScriptException("compile-time exception", new RuntimeException(), Collections.emptyList(), "script", "mockscript"); From 3542b99b32f896e1fa58b7d4ab0b1a6b87f6bb20 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 11:44:02 -0700 Subject: [PATCH 4/9] fix docs and more tests --- docs/build.gradle | 10 ++++---- .../painless-getting-started.asciidoc | 24 +++++++++---------- .../diversified-sampler-aggregation.asciidoc | 2 +- .../bucket/range-aggregation.asciidoc | 6 ++--- .../significantterms-aggregation.asciidoc | 2 +- .../bucket/terms-aggregation.asciidoc | 6 ++--- .../metrics/avg-aggregation.asciidoc | 6 ++--- .../metrics/cardinality-aggregation.asciidoc | 4 ++-- .../extendedstats-aggregation.asciidoc | 6 ++--- .../metrics/max-aggregation.asciidoc | 6 ++--- .../metrics/min-aggregation.asciidoc | 6 ++--- .../metrics/percentile-aggregation.asciidoc | 4 ++-- .../percentile-rank-aggregation.asciidoc | 4 ++-- .../scripted-metric-aggregation.asciidoc | 8 +++---- .../metrics/stats-aggregation.asciidoc | 6 ++--- .../metrics/sum-aggregation.asciidoc | 6 ++--- .../metrics/tophits-aggregation.asciidoc | 2 +- .../metrics/valuecount-aggregation.asciidoc | 4 ++-- docs/reference/aggregations/pipeline.asciidoc | 2 +- docs/reference/docs/bulk.asciidoc | 2 +- docs/reference/docs/reindex.asciidoc | 6 ++--- docs/reference/docs/update-by-query.asciidoc | 8 +++---- docs/reference/docs/update.asciidoc | 8 +++---- docs/reference/ingest/ingest-node.asciidoc | 4 ++-- .../mapping/fields/index-field.asciidoc | 2 +- .../mapping/fields/parent-field.asciidoc | 2 +- .../mapping/fields/type-field.asciidoc | 2 +- .../mapping/fields/uid-field.asciidoc | 2 +- docs/reference/mapping/types/boolean.asciidoc | 2 +- .../modules/scripting/engine.asciidoc | 2 +- .../modules/scripting/fields.asciidoc | 8 +++---- .../modules/scripting/using.asciidoc | 20 ++++++++-------- .../query-dsl/function-score-query.asciidoc | 4 ++-- .../reference/query-dsl/script-query.asciidoc | 4 ++-- docs/reference/search/multi-search.asciidoc | 4 ++-- .../reference/search/request/rescore.asciidoc | 2 +- .../search/request/script-fields.asciidoc | 4 ++-- docs/reference/search/request/sort.asciidoc | 2 +- .../reference/search/search-template.asciidoc | 24 +++++++++---------- .../search/suggesters/phrase-suggest.asciidoc | 2 +- .../test/painless/16_update2.yml | 8 +++---- .../test/upgraded_cluster/10_basic.yml | 22 ++++++++--------- .../50_script_processor_using_painless.yml | 2 +- 43 files changed, 130 insertions(+), 130 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index b52c7dee94da1..339b39c8a25d0 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -428,7 +428,7 @@ buildRestTests.setups['stored_example_script'] = ''' - do: put_script: id: "my_script" - body: { "script": { "lang": "painless", "code": "doc[params.field].value" } } + body: { "script": { "lang": "painless", "source": "doc[params.field].value" } } - match: { acknowledged: true } ''' @@ -436,24 +436,24 @@ buildRestTests.setups['stored_scripted_metric_script'] = ''' - do: put_script: id: "my_init_script" - body: { "script": { "lang": "painless", "code": "params._agg.transactions = []" } } + body: { "script": { "lang": "painless", "source": "params._agg.transactions = []" } } - match: { acknowledged: true } - do: put_script: id: "my_map_script" - body: { "script": { "lang": "painless", "code": "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } } + body: { "script": { "lang": "painless", "source": "params._agg.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } } - match: { acknowledged: true } - do: put_script: id: "my_combine_script" - body: { "script": { "lang": "painless", "code": "double profit = 0;for (t in params._agg.transactions) { profit += t; } return profit" } } + body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in params._agg.transactions) { profit += t; } return profit" } } - match: { acknowledged: true } - do: put_script: id: "my_reduce_script" - body: { "script": { "lang": "painless", "code": "double profit = 0;for (a in params._aggs) { profit += a; } return profit" } } + body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in params._aggs) { profit += a; } return profit" } } - match: { acknowledged: true } ''' diff --git a/docs/painless/painless-getting-started.asciidoc b/docs/painless/painless-getting-started.asciidoc index f805971ff8f36..7948e90991fe1 100644 --- a/docs/painless/painless-getting-started.asciidoc +++ b/docs/painless/painless-getting-started.asciidoc @@ -55,7 +55,7 @@ GET hockey/_search "script_score": { "script": { "lang": "painless", - "inline": "int total = 0; for (int i = 0; i < doc['goals'].length; ++i) { total += doc['goals'][i]; } return total;" + "source": "int total = 0; for (int i = 0; i < doc['goals'].length; ++i) { total += doc['goals'][i]; } return total;" } } } @@ -77,7 +77,7 @@ GET hockey/_search "total_goals": { "script": { "lang": "painless", - "inline": "int total = 0; for (int i = 0; i < doc['goals'].length; ++i) { total += doc['goals'][i]; } return total;" + "source": "int total = 0; for (int i = 0; i < doc['goals'].length; ++i) { total += doc['goals'][i]; } return total;" } } } @@ -101,7 +101,7 @@ GET hockey/_search "order": "asc", "script": { "lang": "painless", - "inline": "doc['first.keyword'].value + ' ' + doc['last.keyword'].value" + "source": "doc['first.keyword'].value + ' ' + doc['last.keyword'].value" } } } @@ -141,7 +141,7 @@ POST hockey/player/1/_update { "script": { "lang": "painless", - "inline": "ctx._source.last = params.last", + "source": "ctx._source.last = params.last", "params": { "last": "hockey" } @@ -159,7 +159,7 @@ POST hockey/player/1/_update { "script": { "lang": "painless", - "inline": "ctx._source.last = params.last; ctx._source.nick = params.nick", + "source": "ctx._source.last = params.last; ctx._source.nick = params.nick", "params": { "last": "gaudreau", "nick": "hockey" @@ -189,7 +189,7 @@ GET hockey/_search "script_fields": { "birth_year": { "script": { - "inline": "doc.born.value.year" + "source": "doc.born.value.year" } } } @@ -230,7 +230,7 @@ POST hockey/player/_update_by_query { "script": { "lang": "painless", - "inline": "if (ctx._source.last =~ /b/) {ctx._source.last += \"matched\"} else {ctx.op = 'noop'}" + "source": "if (ctx._source.last =~ /b/) {ctx._source.last += \"matched\"} else {ctx.op = 'noop'}" } } ---------------------------------------------------------------- @@ -245,7 +245,7 @@ POST hockey/player/_update_by_query { "script": { "lang": "painless", - "inline": "if (ctx._source.last ==~ /[^aeiou].*[aeiou]/) {ctx._source.last += \"matched\"} else {ctx.op = 'noop'}" + "source": "if (ctx._source.last ==~ /[^aeiou].*[aeiou]/) {ctx._source.last += \"matched\"} else {ctx.op = 'noop'}" } } ---------------------------------------------------------------- @@ -260,7 +260,7 @@ POST hockey/player/_update_by_query { "script": { "lang": "painless", - "inline": "ctx._source.last = /[aeiou]/.matcher(ctx._source.last).replaceAll('')" + "source": "ctx._source.last = /[aeiou]/.matcher(ctx._source.last).replaceAll('')" } } ---------------------------------------------------------------- @@ -276,7 +276,7 @@ POST hockey/player/_update_by_query { "script": { "lang": "painless", - "inline": "ctx._source.last = /n([aeiou])/.matcher(ctx._source.last).replaceAll('$1')" + "source": "ctx._source.last = /n([aeiou])/.matcher(ctx._source.last).replaceAll('$1')" } } ---------------------------------------------------------------- @@ -298,7 +298,7 @@ POST hockey/player/_update_by_query { "script": { "lang": "painless", - "inline": "ctx._source.last = ctx._source.last.replaceAll(/[aeiou]/, m -> m.group().toUpperCase(Locale.ROOT))" + "source": "ctx._source.last = ctx._source.last.replaceAll(/[aeiou]/, m -> m.group().toUpperCase(Locale.ROOT))" } } ---------------------------------------------------------------- @@ -313,7 +313,7 @@ POST hockey/player/_update_by_query { "script": { "lang": "painless", - "inline": "ctx._source.last = ctx._source.last.replaceFirst(/[aeiou]/, m -> m.group().toUpperCase(Locale.ROOT))" + "source": "ctx._source.last = ctx._source.last.replaceFirst(/[aeiou]/, m -> m.group().toUpperCase(Locale.ROOT))" } } ---------------------------------------------------------------- diff --git a/docs/reference/aggregations/bucket/diversified-sampler-aggregation.asciidoc b/docs/reference/aggregations/bucket/diversified-sampler-aggregation.asciidoc index 6ef7196f4ac07..8366e79787691 100644 --- a/docs/reference/aggregations/bucket/diversified-sampler-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/diversified-sampler-aggregation.asciidoc @@ -110,7 +110,7 @@ POST /stackoverflow/_search?size=0 "max_docs_per_value" : 3, "script" : { "lang": "painless", - "inline": "doc['tags'].values.hashCode()" + "source": "doc['tags'].values.hashCode()" } }, "aggs": { diff --git a/docs/reference/aggregations/bucket/range-aggregation.asciidoc b/docs/reference/aggregations/bucket/range-aggregation.asciidoc index 63d4c04eea486..7ce8ec699f0de 100644 --- a/docs/reference/aggregations/bucket/range-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/range-aggregation.asciidoc @@ -136,7 +136,7 @@ It is also possible to customize the key for each range: "range" : { "script" : { "lang": "painless", - "inline": "doc['price'].value" + "source": "doc['price'].value" }, "ranges" : [ { "to" : 50 }, @@ -158,7 +158,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "price_ranges" : { "range" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "field": "price" } @@ -187,7 +187,7 @@ Lets say the product prices are in USD but we would like to get the price ranges "field" : "price", "script" : { "lang": "painless", - "inline": "_value * params.conversion_rate", + "source": "_value * params.conversion_rate", "params" : { "conversion_rate" : 0.8 } diff --git a/docs/reference/aggregations/bucket/significantterms-aggregation.asciidoc b/docs/reference/aggregations/bucket/significantterms-aggregation.asciidoc index a927a2165ecaa..ba8bce6736995 100644 --- a/docs/reference/aggregations/bucket/significantterms-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/significantterms-aggregation.asciidoc @@ -358,7 +358,7 @@ Customized scores can be implemented via a script: "script_heuristic": { "script": { "lang": "painless", - "inline": "params._subset_freq/(params._superset_freq - params._subset_freq + 1)" + "source": "params._subset_freq/(params._superset_freq - params._subset_freq + 1)" } } -------------------------------------------------- diff --git a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc index 7346af50daba4..8b32220255b9e 100644 --- a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc @@ -460,7 +460,7 @@ Generating the terms using a script: "genres" : { "terms" : { "script" : { - "inline": "doc['genre'].value", + "source": "doc['genre'].value", "lang": "painless" } } @@ -478,7 +478,7 @@ This will interpret the `script` parameter as an `inline` script with the defaul "genres" : { "terms" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "field": "genre" } @@ -499,7 +499,7 @@ This will interpret the `script` parameter as an `inline` script with the defaul "terms" : { "field" : "gender", "script" : { - "inline" : "'Genre: ' +_value" + "source" : "'Genre: ' +_value" "lang" : "painless" } } diff --git a/docs/reference/aggregations/metrics/avg-aggregation.asciidoc b/docs/reference/aggregations/metrics/avg-aggregation.asciidoc index 5e3b93c315226..0607dadf85729 100644 --- a/docs/reference/aggregations/metrics/avg-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/avg-aggregation.asciidoc @@ -47,7 +47,7 @@ POST /exams/_search?size=0 "avg_grade" : { "avg" : { "script" : { - "inline" : "doc.grade.value" + "source" : "doc.grade.value" } } } @@ -67,7 +67,7 @@ POST /exams/_search?size=0 "avg_grade" : { "avg" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "field": "grade" } @@ -94,7 +94,7 @@ POST /exams/_search?size=0 "field" : "grade", "script" : { "lang": "painless", - "inline": "_value * params.correction", + "source": "_value * params.correction", "params" : { "correction" : 1.2 } diff --git a/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc b/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc index 3b613425dce91..8b5c05900b38f 100644 --- a/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc @@ -187,7 +187,7 @@ POST /sales/_search?size=0 "cardinality" : { "script": { "lang": "painless", - "inline": "doc['type'].value + ' ' + doc['promoted'].value" + "source": "doc['type'].value + ' ' + doc['promoted'].value" } } } @@ -207,7 +207,7 @@ POST /sales/_search?size=0 "type_promoted_count" : { "cardinality" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "type_field": "type", "promoted_field": "promoted" diff --git a/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc b/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc index 5a2b043ee058d..b259fac7d77b0 100644 --- a/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc @@ -89,7 +89,7 @@ Computing the grades stats based on a script: "grades_stats" : { "extended_stats" : { "script" : { - "inline" : "doc['grade'].value", + "source" : "doc['grade'].value", "lang" : "painless" } } @@ -109,7 +109,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "grades_stats" : { "extended_stats" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "field": "grade" } @@ -136,7 +136,7 @@ It turned out that the exam was way above the level of the students and a grade "field" : "grade", "script" : { "lang" : "painless", - "inline": "_value * params.correction", + "source": "_value * params.correction", "params" : { "correction" : 1.2 } diff --git a/docs/reference/aggregations/metrics/max-aggregation.asciidoc b/docs/reference/aggregations/metrics/max-aggregation.asciidoc index a9c91284056e7..cd9f4282e4d72 100644 --- a/docs/reference/aggregations/metrics/max-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/max-aggregation.asciidoc @@ -56,7 +56,7 @@ POST /sales/_search "max_price" : { "max" : { "script" : { - "inline" : "doc.price.value" + "source" : "doc.price.value" } } } @@ -77,7 +77,7 @@ POST /sales/_search "max_price" : { "max" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "field": "price" } @@ -106,7 +106,7 @@ POST /sales/_search "max" : { "field" : "price", "script" : { - "inline" : "_value * params.conversion_rate", + "source" : "_value * params.conversion_rate", "params" : { "conversion_rate" : 1.2 } diff --git a/docs/reference/aggregations/metrics/min-aggregation.asciidoc b/docs/reference/aggregations/metrics/min-aggregation.asciidoc index ac9f493e49314..9eaa8a7372688 100644 --- a/docs/reference/aggregations/metrics/min-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/min-aggregation.asciidoc @@ -57,7 +57,7 @@ POST /sales/_search "min_price" : { "min" : { "script" : { - "inline" : "doc.price.value" + "source" : "doc.price.value" } } } @@ -78,7 +78,7 @@ POST /sales/_search "min_price" : { "min" : { "script" : { - "stored": "my_script", + "id": "my_script", "params": { "field": "price" } @@ -107,7 +107,7 @@ POST /sales/_search "min" : { "field" : "price", "script" : { - "inline" : "_value * params.conversion_rate", + "source" : "_value * params.conversion_rate", "params" : { "conversion_rate" : 1.2 } diff --git a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc index ce275a6f3beaf..9c93a4bada72e 100644 --- a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc @@ -173,7 +173,7 @@ a script to convert them on-the-fly: "percentiles" : { "script" : { "lang": "painless", - "inline": "doc['load_time'].value / params.timeUnit", <1> + "source": "doc['load_time'].value / params.timeUnit", <1> "params" : { "timeUnit" : 1000 <2> } @@ -196,7 +196,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "load_time_outlier" : { "percentiles" : { "script" : { - "stored": "my_script", + "id": "my_script", "params" : { "timeUnit" : 1000 } diff --git a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc index a00d0fad799c2..dc5cb8ceeecfe 100644 --- a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc @@ -122,7 +122,7 @@ a script to convert them on-the-fly: "values" : [3, 5], "script" : { "lang": "painless", - "inline": "doc['load_time'].value / params.timeUnit", <1> + "source": "doc['load_time'].value / params.timeUnit", <1> "params" : { "timeUnit" : 1000 <2> } @@ -146,7 +146,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl "percentile_ranks" : { "values" : [3, 5], "script" : { - "stored": "my_script", + "id": "my_script", "params" : { "timeUnit" : 1000 } diff --git a/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc index 3796c2c3c6231..252f193063d12 100644 --- a/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc @@ -60,20 +60,20 @@ POST ledger/_search?size=0 "profit": { "scripted_metric": { "init_script" : { - "stored": "my_init_script" + "id": "my_init_script" }, "map_script" : { - "stored": "my_map_script" + "id": "my_map_script" }, "combine_script" : { - "stored": "my_combine_script" + "id": "my_combine_script" }, "params": { "field": "amount", <1> "_agg": {} <2> }, "reduce_script" : { - "stored": "my_reduce_script" + "id": "my_reduce_script" } } } diff --git a/docs/reference/aggregations/metrics/stats-aggregation.asciidoc b/docs/reference/aggregations/metrics/stats-aggregation.asciidoc index 1892ce45cc181..770b9c523fec6 100644 --- a/docs/reference/aggregations/metrics/stats-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/stats-aggregation.asciidoc @@ -55,7 +55,7 @@ POST /exams/_search?size=0 "stats" : { "script" : { "lang": "painless", - "inline": "doc['grade'].value" + "source": "doc['grade'].value" } } } @@ -75,7 +75,7 @@ POST /exams/_search?size=0 "grades_stats" : { "stats" : { "script" : { - "stored": "my_script", + "id": "my_script", "params" : { "field" : "grade" } @@ -102,7 +102,7 @@ POST /exams/_search?size=0 "field" : "grade", "script" : { "lang": "painless", - "inline": "_value * params.correction", + "source": "_value * params.correction", "params" : { "correction" : 1.2 } diff --git a/docs/reference/aggregations/metrics/sum-aggregation.asciidoc b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc index 975ef163cbcc5..55c1c3f80fac7 100644 --- a/docs/reference/aggregations/metrics/sum-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc @@ -61,7 +61,7 @@ POST /sales/_search?size=0 "hat_prices" : { "sum" : { "script" : { - "inline": "doc.price.value" + "source": "doc.price.value" } } } @@ -88,7 +88,7 @@ POST /sales/_search?size=0 "hat_prices" : { "sum" : { "script" : { - "stored": "my_script", + "id": "my_script", "params" : { "field" : "price" } @@ -122,7 +122,7 @@ POST /sales/_search?size=0 "sum" : { "field" : "price", "script" : { - "inline": "_value * _value" + "source": "_value * _value" } } } diff --git a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc index 6935354c0acee..05fb51e6d8530 100644 --- a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc @@ -198,7 +198,7 @@ relevancy order of the most relevant document in a bucket. "top_hit" : { "max": { "script": { - "inline": "_score" + "source": "_score" } } } diff --git a/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc index 1be6c78047180..8d5c72994c4a5 100644 --- a/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc @@ -48,7 +48,7 @@ POST /sales/_search?size=0 "type_count" : { "value_count" : { "script" : { - "inline" : "doc['type'].value" + "source" : "doc['type'].value" } } } @@ -68,7 +68,7 @@ POST /sales/_search?size=0 "types_count" : { "value_count" : { "script" : { - "stored": "my_script", + "id": "my_script", "params" : { "field" : "type" } diff --git a/docs/reference/aggregations/pipeline.asciidoc b/docs/reference/aggregations/pipeline.asciidoc index 0f3573eaa9ad2..540a5f0ff290e 100644 --- a/docs/reference/aggregations/pipeline.asciidoc +++ b/docs/reference/aggregations/pipeline.asciidoc @@ -167,7 +167,7 @@ POST /sales/_search "count": "categories._bucket_count" <1> }, "script": { - "inline": "params.count != 0" + "source": "params.count != 0" } } } diff --git a/docs/reference/docs/bulk.asciidoc b/docs/reference/docs/bulk.asciidoc index 0a0e9e4bfc30b..513a5ec61bb74 100644 --- a/docs/reference/docs/bulk.asciidoc +++ b/docs/reference/docs/bulk.asciidoc @@ -260,7 +260,7 @@ POST _bulk { "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} } { "doc" : {"field" : "value"} } { "update" : { "_id" : "0", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} } -{ "script" : { "inline": "ctx._source.counter += params.param1", "lang" : "painless", "params" : {"param1" : 1}}, "upsert" : {"counter" : 1}} +{ "script" : { "source": "ctx._source.counter += params.param1", "lang" : "painless", "params" : {"param1" : 1}}, "upsert" : {"counter" : 1}} { "update" : {"_id" : "2", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} } { "doc" : {"field" : "value"}, "doc_as_upsert" : true } { "update" : {"_id" : "3", "_type" : "type1", "_index" : "index1", "_source" : true} } diff --git a/docs/reference/docs/reindex.asciidoc b/docs/reference/docs/reindex.asciidoc index bd670fdf84b2f..64ea0cdc4867e 100644 --- a/docs/reference/docs/reindex.asciidoc +++ b/docs/reference/docs/reindex.asciidoc @@ -263,7 +263,7 @@ POST _reindex "version_type": "external" }, "script": { - "inline": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}", + "source": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}", "lang": "painless" } } @@ -748,7 +748,7 @@ POST _reindex "index": "test2" }, "script": { - "inline": "ctx._source.tag = ctx._source.remove(\"flag\")" + "source": "ctx._source.tag = ctx._source.remove(\"flag\")" } } -------------------------------------------------- @@ -965,7 +965,7 @@ POST _reindex }, "script": { "lang": "painless", - "inline": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'" + "source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'" } } ---------------------------------------------------------------- diff --git a/docs/reference/docs/update-by-query.asciidoc b/docs/reference/docs/update-by-query.asciidoc index 23ce6589f3d58..28c250dcfe193 100644 --- a/docs/reference/docs/update-by-query.asciidoc +++ b/docs/reference/docs/update-by-query.asciidoc @@ -106,7 +106,7 @@ will increment the `likes` field on all of kimchy's tweets: POST twitter/_update_by_query { "script": { - "inline": "ctx._source.likes++", + "source": "ctx._source.likes++", "lang": "painless" }, "query": { @@ -418,7 +418,7 @@ POST twitter/_update_by_query "max": 2 }, "script": { - "inline": "ctx._source['extra'] = 'test'" + "source": "ctx._source['extra'] = 'test'" } } POST twitter/_update_by_query @@ -428,7 +428,7 @@ POST twitter/_update_by_query "max": 2 }, "script": { - "inline": "ctx._source['extra'] = 'test'" + "source": "ctx._source['extra'] = 'test'" } } ---------------------------------------------------------------- @@ -469,7 +469,7 @@ You can also let update-by-query automatically parallelize using POST twitter/_update_by_query?refresh&slices=5 { "script": { - "inline": "ctx._source['extra'] = 'test'" + "source": "ctx._source['extra'] = 'test'" } } ---------------------------------------------------------------- diff --git a/docs/reference/docs/update.asciidoc b/docs/reference/docs/update.asciidoc index efa9fa0017715..6a3a39cf5cd43 100644 --- a/docs/reference/docs/update.asciidoc +++ b/docs/reference/docs/update.asciidoc @@ -35,7 +35,7 @@ Now, we can execute a script that would increment the counter: POST test/type1/1/_update { "script" : { - "inline": "ctx._source.counter += params.count", + "source": "ctx._source.counter += params.count", "lang": "painless", "params" : { "count" : 4 @@ -54,7 +54,7 @@ will still add it, since its a list): POST test/type1/1/_update { "script" : { - "inline": "ctx._source.tags.add(params.tag)", + "source": "ctx._source.tags.add(params.tag)", "lang": "painless", "params" : { "tag" : "blue" @@ -102,7 +102,7 @@ the doc if the `tags` field contain `green`, otherwise it does nothing POST test/type1/1/_update { "script" : { - "inline": "if (ctx._source.tags.contains(params.tag)) { ctx.op = 'delete' } else { ctx.op = 'none' }", + "source": "if (ctx._source.tags.contains(params.tag)) { ctx.op = 'delete' } else { ctx.op = 'none' }", "lang": "painless", "params" : { "tag" : "green" @@ -203,7 +203,7 @@ will be inserted as a new document. If the document does exist, then the POST test/type1/1/_update { "script" : { - "inline": "ctx._source.counter += params.count", + "source": "ctx._source.counter += params.count", "lang": "painless", "params" : { "count" : 4 diff --git a/docs/reference/ingest/ingest-node.asciidoc b/docs/reference/ingest/ingest-node.asciidoc index 09856bee7aeda..b667342c82304 100644 --- a/docs/reference/ingest/ingest-node.asciidoc +++ b/docs/reference/ingest/ingest-node.asciidoc @@ -1730,7 +1730,7 @@ numeric fields `field_a` and `field_b` multiplied by the parameter param_c: { "script": { "lang": "painless", - "inline": "ctx.field_a_plus_b_times_c = (ctx.field_a + ctx.field_b) * params.param_c", + "source": "ctx.field_a_plus_b_times_c = (ctx.field_a + ctx.field_b) * params.param_c", "params": { "param_c": 10 } @@ -1751,7 +1751,7 @@ PUT _ingest/pipeline/my_index "processors": [ { "script": { - "inline": " ctx._index = 'my_index'; ctx._type = 'my_type' " + "source": " ctx._index = 'my_index'; ctx._type = 'my_type' " } } ] diff --git a/docs/reference/mapping/fields/index-field.asciidoc b/docs/reference/mapping/fields/index-field.asciidoc index cd285c4255718..1cd6b05a93d7a 100644 --- a/docs/reference/mapping/fields/index-field.asciidoc +++ b/docs/reference/mapping/fields/index-field.asciidoc @@ -52,7 +52,7 @@ GET index_1,index_2/_search "index_name": { "script": { "lang": "painless", - "inline": "doc['_index']" <4> + "source": "doc['_index']" <4> } } } diff --git a/docs/reference/mapping/fields/parent-field.asciidoc b/docs/reference/mapping/fields/parent-field.asciidoc index affb962df475b..873ed888da513 100644 --- a/docs/reference/mapping/fields/parent-field.asciidoc +++ b/docs/reference/mapping/fields/parent-field.asciidoc @@ -87,7 +87,7 @@ GET my_index/_search "script_fields": { "parent": { "script": { - "inline": "doc['_parent']" <3> + "source": "doc['_parent']" <3> } } } diff --git a/docs/reference/mapping/fields/type-field.asciidoc b/docs/reference/mapping/fields/type-field.asciidoc index fb577b5a03f35..5eb620b6420ca 100644 --- a/docs/reference/mapping/fields/type-field.asciidoc +++ b/docs/reference/mapping/fields/type-field.asciidoc @@ -54,7 +54,7 @@ GET my_index/_search "type": { "script": { "lang": "painless", - "inline": "doc['_type']" <4> + "source": "doc['_type']" <4> } } } diff --git a/docs/reference/mapping/fields/uid-field.asciidoc b/docs/reference/mapping/fields/uid-field.asciidoc index a1a3e8d14bf2a..7ab97a305d763 100644 --- a/docs/reference/mapping/fields/uid-field.asciidoc +++ b/docs/reference/mapping/fields/uid-field.asciidoc @@ -55,7 +55,7 @@ GET my_index/_search "UID": { "script": { "lang": "painless", - "inline": "doc['_uid']" <4> + "source": "doc['_uid']" <4> } } } diff --git a/docs/reference/mapping/types/boolean.asciidoc b/docs/reference/mapping/types/boolean.asciidoc index 5f521922655c5..4fe577b9f632e 100644 --- a/docs/reference/mapping/types/boolean.asciidoc +++ b/docs/reference/mapping/types/boolean.asciidoc @@ -78,7 +78,7 @@ GET my_index/_search "is_published": { "script": { "lang": "painless", - "inline": "doc['is_published'].value" + "source": "doc['is_published'].value" } } } diff --git a/docs/reference/modules/scripting/engine.asciidoc b/docs/reference/modules/scripting/engine.asciidoc index 207722d8febf7..be1035991526e 100644 --- a/docs/reference/modules/scripting/engine.asciidoc +++ b/docs/reference/modules/scripting/engine.asciidoc @@ -39,7 +39,7 @@ POST /_search { "script_score": { "script": { - "inline": "pure_df", + "source": "pure_df", "lang" : "expert_scripts", "params": { "field": "body", diff --git a/docs/reference/modules/scripting/fields.asciidoc b/docs/reference/modules/scripting/fields.asciidoc index e8019f01d1cec..afb5055a4ddb9 100644 --- a/docs/reference/modules/scripting/fields.asciidoc +++ b/docs/reference/modules/scripting/fields.asciidoc @@ -68,7 +68,7 @@ GET my_index/_search "script_score": { "script": { "lang": "expression", - "inline": "_score * doc['popularity']" + "source": "_score * doc['popularity']" } } } @@ -100,7 +100,7 @@ GET my_index/_search "sales_price": { "script": { "lang": "expression", - "inline": "doc['cost_price'] * markup", + "source": "doc['cost_price'] * markup", "params": { "markup": 0.2 } @@ -195,13 +195,13 @@ GET my_index/_search "source": { "script": { "lang": "painless", - "inline": "params._source.title + ' ' + params._source.first_name + ' ' + params._source.last_name" <2> + "source": "params._source.title + ' ' + params._source.first_name + ' ' + params._source.last_name" <2> } }, "stored_fields": { "script": { "lang": "painless", - "inline": "params._fields['first_name'].value + ' ' + params._fields['last_name'].value" + "source": "params._fields['first_name'].value + ' ' + params._fields['last_name'].value" } } } diff --git a/docs/reference/modules/scripting/using.asciidoc b/docs/reference/modules/scripting/using.asciidoc index ec9f74c0af642..7e996637ba8c0 100644 --- a/docs/reference/modules/scripting/using.asciidoc +++ b/docs/reference/modules/scripting/using.asciidoc @@ -8,13 +8,13 @@ the same pattern: ------------------------------------- "script": { "lang": "...", <1> - "inline" | "stored": "...", <2> + "source" | "id": "...", <2> "params": { ... } <3> } ------------------------------------- // NOTCONSOLE <1> The language the script is written in, which defaults to `painless`. -<2> The script itself which may be specified as `inline` or `stored`. +<2> The script itself which may be specified as `source` for an inline script or `id` for a stored script. <3> Any named parameters that should be passed into the script. For example, the following script is used in a search request to return a @@ -33,7 +33,7 @@ GET my_index/_search "my_doubled_field": { "script": { "lang": "expression", - "inline": "doc['my_field'] * multiplier", + "source": "doc['my_field'] * multiplier", "params": { "multiplier": 2 } @@ -55,10 +55,10 @@ GET my_index/_search setting `script.default_lang` to the appropriate language. -`inline`, `stored`:: +`source`, `id`:: Specifies the source of the script. An `inline` script is specified - `inline` as in the example above. A `stored` script is specified `stored` + `source` as in the example above. A `stored` script is specified `id` and is retrieved from the cluster state (see <>). @@ -82,7 +82,7 @@ multipliers, don't hard-code the multiplier into the script: [source,js] ---------------------- - "inline": "doc['my_field'] * 2" + "source": "doc['my_field'] * 2" ---------------------- // NOTCONSOLE @@ -90,7 +90,7 @@ Instead, pass it in as a named parameter: [source,js] ---------------------- - "inline": "doc['my_field'] * multiplier", + "source": "doc['my_field'] * multiplier", "params": { "multiplier": 2 } @@ -150,7 +150,7 @@ POST _scripts/calculate-score { "script": { "lang": "painless", - "code": "Math.log(_score * 2) + params.my_modifier" + "source": "Math.log(_score * 2) + params.my_modifier" } } ----------------------------------- @@ -165,7 +165,7 @@ GET _scripts/calculate-score // CONSOLE // TEST[continued] -Stored scripts can be used by specifying the `stored` parameters as follows: +Stored scripts can be used by specifying the `id` parameters as follows: [source,js] -------------------------------------------------- @@ -174,7 +174,7 @@ GET _search "query": { "script": { "script": { - "stored": "calculate-score", + "id": "calculate-score", "params": { "my_modifier": 2 } diff --git a/docs/reference/query-dsl/function-score-query.asciidoc b/docs/reference/query-dsl/function-score-query.asciidoc index e996b833f5804..9f752b191bba2 100644 --- a/docs/reference/query-dsl/function-score-query.asciidoc +++ b/docs/reference/query-dsl/function-score-query.asciidoc @@ -143,7 +143,7 @@ GET /_search }, "script_score" : { "script" : { - "inline": "Math.log(2 + doc['likes'].value)" + "source": "Math.log(2 + doc['likes'].value)" } } } @@ -176,7 +176,7 @@ GET /_search "a": 5, "b": 1.2 }, - "inline": "params.a / Math.pow(params.b, doc['likes'].value)" + "source": "params.a / Math.pow(params.b, doc['likes'].value)" } } } diff --git a/docs/reference/query-dsl/script-query.asciidoc b/docs/reference/query-dsl/script-query.asciidoc index db82375abe09e..a2bb49212034e 100644 --- a/docs/reference/query-dsl/script-query.asciidoc +++ b/docs/reference/query-dsl/script-query.asciidoc @@ -14,7 +14,7 @@ GET /_search "must" : { "script" : { "script" : { - "inline": "doc['num1'].value > 1", + "source": "doc['num1'].value > 1", "lang": "painless" } } @@ -41,7 +41,7 @@ GET /_search "must" : { "script" : { "script" : { - "inline" : "doc['num1'].value > params.param1", + "source" : "doc['num1'].value > params.param1", "lang" : "painless", "params" : { "param1" : 5 diff --git a/docs/reference/search/multi-search.asciidoc b/docs/reference/search/multi-search.asciidoc index f9188808661b6..90f5c09756821 100644 --- a/docs/reference/search/multi-search.asciidoc +++ b/docs/reference/search/multi-search.asciidoc @@ -103,9 +103,9 @@ also provides support for templates. Submit them like follows: ----------------------------------------------- GET _msearch/template {"index" : "twitter"} -{ "inline" : "{ \"query\": { \"match\": { \"message\" : \"{{keywords}}\" } } } }", "params": { "query_type": "match", "keywords": "some message" } } +{ "source" : "{ \"query\": { \"match\": { \"message\" : \"{{keywords}}\" } } } }", "params": { "query_type": "match", "keywords": "some message" } } {"index" : "twitter"} -{ "inline" : "{ \"query\": { \"match_{{template}}\": {} } }", "params": { "template": "all" } } +{ "source" : "{ \"query\": { \"match_{{template}}\": {} } }", "params": { "template": "all" } } ----------------------------------------------- // CONSOLE // TEST[setup:twitter] diff --git a/docs/reference/search/request/rescore.asciidoc b/docs/reference/search/request/rescore.asciidoc index 42d160803d785..204960544a688 100644 --- a/docs/reference/search/request/rescore.asciidoc +++ b/docs/reference/search/request/rescore.asciidoc @@ -121,7 +121,7 @@ POST /_search "function_score" : { "script_score": { "script": { - "inline": "Math.log10(doc.likes.value + 2)" + "source": "Math.log10(doc.likes.value + 2)" } } } diff --git a/docs/reference/search/request/script-fields.asciidoc b/docs/reference/search/request/script-fields.asciidoc index c8886f779a5c6..403cad9c5dd01 100644 --- a/docs/reference/search/request/script-fields.asciidoc +++ b/docs/reference/search/request/script-fields.asciidoc @@ -15,13 +15,13 @@ GET /_search "test1" : { "script" : { "lang": "painless", - "inline": "doc['my_field_name'].value * 2" + "source": "doc['my_field_name'].value * 2" } }, "test2" : { "script" : { "lang": "painless", - "inline": "doc['my_field_name'].value * factor", + "source": "doc['my_field_name'].value * factor", "params" : { "factor" : 2.0 } diff --git a/docs/reference/search/request/sort.asciidoc b/docs/reference/search/request/sort.asciidoc index 049b83b08c882..89ad7ea2c479e 100644 --- a/docs/reference/search/request/sort.asciidoc +++ b/docs/reference/search/request/sort.asciidoc @@ -406,7 +406,7 @@ GET /_search "type" : "number", "script" : { "lang": "painless", - "inline": "doc['field_name'].value * params.factor", + "source": "doc['field_name'].value * params.factor", "params" : { "factor" : 1.1 } diff --git a/docs/reference/search/search-template.asciidoc b/docs/reference/search/search-template.asciidoc index aff8797765750..ee7fa61885f03 100644 --- a/docs/reference/search/search-template.asciidoc +++ b/docs/reference/search/search-template.asciidoc @@ -8,7 +8,7 @@ before they are executed and fill existing templates with template parameters. ------------------------------------------ GET _search/template { - "inline" : { + "source" : { "query": { "match" : { "{{my_field}}" : "{{my_value}}" } }, "size" : "{{my_size}}" }, @@ -41,7 +41,7 @@ disable scripts per type and context as described in the ------------------------------------------ GET _search/template { - "inline": { + "source": { "query": { "term": { "message": "{{query_string}}" @@ -66,7 +66,7 @@ like maps and array to their JSON representation: ------------------------------------------ GET _search/template { - "inline": "{ \"query\": { \"terms\": {{#toJson}}statuses{{/toJson}} }}", + "source": "{ \"query\": { \"terms\": {{#toJson}}statuses{{/toJson}} }}", "params": { "statuses" : { "status": [ "pending", "published" ] @@ -99,7 +99,7 @@ A more complex example substitutes an array of JSON objects: ------------------------------------------ GET _search/template { - "inline": "{\"query\":{\"bool\":{\"must\": {{#toJson}}clauses{{/toJson}} }}}", + "source": "{\"query\":{\"bool\":{\"must\": {{#toJson}}clauses{{/toJson}} }}}", "params": { "clauses": [ { "term": { "user" : "foo" } }, @@ -145,7 +145,7 @@ values of an array as a comma delimited string: ------------------------------------------ GET _search/template { - "inline": { + "source": { "query": { "match": { "emails": "{{#join}}emails{{/join}}" @@ -179,7 +179,7 @@ The function also accepts a custom delimiter: ------------------------------------------ GET _search/template { - "inline": { + "source": { "query": { "range": { "born": { @@ -228,7 +228,7 @@ A default value is written as `{{var}}{{^var}}default{{/var}}` for instance: [source,js] ------------------------------------------ { - "inline": { + "source": { "query": { "range": { "line_no": { @@ -348,7 +348,7 @@ via the REST API, should be written as a string: [source,js] -------------------- -"inline": "{\"query\":{\"bool\":{\"must\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}" +"source": "{\"query\":{\"bool\":{\"must\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}" -------------------- // NOTCONSOLE ================================== @@ -366,7 +366,7 @@ As an example, it is useful to encode a URL: ------------------------------------------ GET _render/template { - "inline" : { + "source" : { "query" : { "term": { "http_access_log": "{{#url}}{{host}}/{{page}}{{/url}}" @@ -507,7 +507,7 @@ A template can be rendered in a response with given parameters using ------------------------------------------ GET _render/template { - "inline": "{ \"query\": { \"terms\": {{#toJson}}statuses{{/toJson}} }}", + "source": "{ \"query\": { \"terms\": {{#toJson}}statuses{{/toJson}} }}", "params": { "statuses" : { "status": [ "pending", "published" ] @@ -616,9 +616,9 @@ stored and file templates. Here is an example: -------------------------------------------------- $ cat requests {"index": "test"} -{"inline": {"query": {"match": {"user" : "{{username}}" }}}, "params": {"username": "john"}} <1> +{"source": {"query": {"match": {"user" : "{{username}}" }}}, "params": {"username": "john"}} <1> {"index": "_all", "types": "accounts"} -{"inline": {"query": {"{{query_type}}": {"name": "{{name}}" }}}, "params": {"query_type": "match_phrase_prefix", "name": "Smith"}} +{"source": {"query": {"{{query_type}}": {"name": "{{name}}" }}}, "params": {"query_type": "match_phrase_prefix", "name": "Smith"}} {"index": "_all"} {"id": "template_1", "params": {"query_string": "search for these words" }} <2> diff --git a/docs/reference/search/suggesters/phrase-suggest.asciidoc b/docs/reference/search/suggesters/phrase-suggest.asciidoc index 53c0c9be4e467..92138e7ecdfe0 100644 --- a/docs/reference/search/suggesters/phrase-suggest.asciidoc +++ b/docs/reference/search/suggesters/phrase-suggest.asciidoc @@ -241,7 +241,7 @@ POST _search } ], "collate": { "query": { <1> - "inline" : { + "source" : { "match": { "{{field_name}}" : "{{suggestion}}" <2> } diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml index c96bec29ecf62..c55876a6ae231 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/16_update2.yml @@ -6,7 +6,7 @@ - do: put_script: id: "1" - body: { "script": {"lang": "painless", "code": "_score * doc['myParent.weight'].value" } } + body: { "script": {"lang": "painless", "source": "_score * doc['myParent.weight'].value" } } - match: { acknowledged: true } - do: @@ -14,7 +14,7 @@ lang: "1" - match: { found: true } - match: { _id: "1" } - - match: { "script": {"lang": "painless", "code": "_score * doc['myParent.weight'].value"} } + - match: { "script": {"lang": "painless", "source": "_score * doc['myParent.weight'].value"} } - do: catch: missing @@ -39,11 +39,11 @@ put_script: id: "1" context: "search" - body: { "script": {"lang": "painless", "code": "_score * foo bar + doc['myParent.weight'].value"} } + body: { "script": {"lang": "painless", "source": "_score * foo bar + doc['myParent.weight'].value"} } - do: catch: /compile error/ put_script: id: "1" context: "search" - body: { "script": {"lang": "painless", "code": "_score * foo bar + doc['myParent.weight'].value"} } + body: { "script": {"lang": "painless", "source": "_score * foo bar + doc['myParent.weight'].value"} } diff --git a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml index 725883e7ed57b..96a3c4674c7e0 100644 --- a/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml +++ b/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml @@ -129,7 +129,7 @@ "query": { "script": { "script": { - "stored": "greater", + "id": "greater", "lang": "painless" } } @@ -137,13 +137,13 @@ "script_fields": { "script_painless": { "script": { - "stored": "value", + "id": "value", "lang": "painless" } }, "script_expressions": { "script": { - "stored": "value", + "id": "value", "lang": "expression" } } @@ -236,7 +236,7 @@ "query": { "script": { "script": { - "stored": "greater", + "id": "greater", "lang": "painless" } } @@ -244,12 +244,12 @@ "script_fields": { "script_painless": { "script": { - "stored": "value" + "id": "value" } }, "script_expressions": { "script": { - "stored": "value", + "id": "value", "lang": "expression" } } @@ -310,7 +310,7 @@ lang: "value" body: { "script": { - "code": "doc['num'].value", + "source": "doc['num'].value", "lang": "painless" } } @@ -353,7 +353,7 @@ lang: "value" body: { "script": { - "code": "doc['num'].value", + "source": "doc['num'].value", "lang": "expression" } } @@ -427,7 +427,7 @@ lang: "value" body: { "script": { - "code": "doc['num'].value", + "source": "doc['num'].value", "lang": "painless" } } @@ -469,14 +469,14 @@ "query": { "script": { "script": { - "stored": "greater" + "id": "greater" } } }, "script_fields": { "script_painless": { "script": { - "stored": "value" + "id": "value" } } }, diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml index b488c62972596..cc6ebac6e9568 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml @@ -48,7 +48,7 @@ { "script": { "lang": "painless", - "code" : "ctx.bytes_total = ctx.bytes_in + ctx.bytes_out" + "source" : "ctx.bytes_total = ctx.bytes_in + ctx.bytes_out" } } - match: { acknowledged: true } From 4fb483bcb242cc7e309a2502e71666eb1cd3f4fa Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 12:39:42 -0700 Subject: [PATCH 5/9] fix stored script output --- .../admin/cluster/RestGetStoredScriptAction.java | 2 +- .../org/elasticsearch/script/StoredScriptSource.java | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java index 693f22c36cf71..f6299fcac58ce 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java @@ -98,7 +98,7 @@ public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuil if (lang == null) { builder.startObject(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName()); builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), source.getLang()); - builder.field(StoredScriptSource.CODE_PARSE_FIELD.getPreferredName(), source.getSource()); + builder.field(StoredScriptSource.SOURCE_PARSE_FIELD.getPreferredName(), source.getSource()); if (source.getOptions().isEmpty() == false) { builder.field(StoredScriptSource.OPTIONS_PARSE_FIELD.getPreferredName(), source.getOptions()); diff --git a/core/src/main/java/org/elasticsearch/script/StoredScriptSource.java b/core/src/main/java/org/elasticsearch/script/StoredScriptSource.java index c4aecbf860975..4c71b05a5082c 100644 --- a/core/src/main/java/org/elasticsearch/script/StoredScriptSource.java +++ b/core/src/main/java/org/elasticsearch/script/StoredScriptSource.java @@ -72,12 +72,7 @@ public class StoredScriptSource extends AbstractDiffable imp /** * Standard {@link ParseField} for source on the inner level. */ - public static final ParseField SOURCE_PARSE_FIELD = new ParseField("source"); - - /** - * Standard {@link ParseField} for source on the inner level. - */ - public static final ParseField CODE_PARSE_FIELD = new ParseField("code"); + public static final ParseField SOURCE_PARSE_FIELD = new ParseField("source", "code"); /** * Standard {@link ParseField} for options on the inner level. @@ -161,8 +156,6 @@ private StoredScriptSource build() { // Defines the fields necessary to parse a Script as XContent using an ObjectParser. PARSER.declareString(Builder::setLang, LANG_PARSE_FIELD); PARSER.declareField(Builder::setSource, parser -> parser, SOURCE_PARSE_FIELD, ValueType.OBJECT_OR_STRING); - // accepting "code" here is for backcompat with version 5.3 to 5.5 - PARSER.declareField(Builder::setSource, parser -> parser, CODE_PARSE_FIELD, ValueType.OBJECT_OR_STRING); PARSER.declareField(Builder::setOptions, XContentParser::mapStrings, OPTIONS_PARSE_FIELD, ValueType.OBJECT); } @@ -442,7 +435,7 @@ public void writeTo(StreamOutput out) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(LANG_PARSE_FIELD.getPreferredName(), lang); - builder.field(CODE_PARSE_FIELD.getPreferredName(), source); + builder.field(SOURCE_PARSE_FIELD.getPreferredName(), source); builder.field(OPTIONS_PARSE_FIELD.getPreferredName(), options); builder.endObject(); From 95dd1aad75150696d58456a23c74e69d808e7042 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 13:40:00 -0700 Subject: [PATCH 6/9] even more test fixes --- core/src/main/java/org/elasticsearch/script/Script.java | 4 +--- .../java/org/elasticsearch/script/StoredScriptTests.java | 9 +++++---- .../rest-api-spec/test/stats/30_single_value_field.yml | 4 ++-- .../rest-api-spec/test/stats/40_multi_value_field.yml | 4 ++-- .../percolator/PercolatorFieldMapperTests.java | 6 +++--- .../test/ingest/50_script_processor_using_painless.yml | 6 +++--- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/script/Script.java b/core/src/main/java/org/elasticsearch/script/Script.java index 6f356b8a5e579..ee4f8e442f405 100644 --- a/core/src/main/java/org/elasticsearch/script/Script.java +++ b/core/src/main/java/org/elasticsearch/script/Script.java @@ -223,9 +223,7 @@ private void setParams(Map params) { */ private Script build(String defaultLang) { if (type == null) { - throw new IllegalArgumentException( - "must specify either code for an [" + ScriptType.INLINE.getParseField().getPreferredName() + "] script " + - "or an id for a [" + ScriptType.STORED.getParseField().getPreferredName() + "] script"); + throw new IllegalArgumentException("must specify either [source] for an inline script or [id] for a stored script"); } if (type == ScriptType.INLINE) { diff --git a/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java b/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java index cad7013dce4ef..6c2a0caf7208b 100644 --- a/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/StoredScriptTests.java @@ -266,10 +266,11 @@ public void testSourceParsing() throws Exception { assertThat(parsed, equalTo(source)); } + assertWarnings("Deprecated field [code] used, expected [source] instead"); // complex script with script object and empty options try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { - builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code") + builder.startObject().field("script").startObject().field("lang", "lang").field("source", "code") .field("options").startObject().endObject().endObject().endObject(); StoredScriptSource parsed = StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON); @@ -280,7 +281,7 @@ public void testSourceParsing() throws Exception { // complex script with embedded template try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { - builder.startObject().field("script").startObject().field("lang", "lang").startObject("code").field("query", "code") + builder.startObject().field("script").startObject().field("lang", "lang").startObject("source").field("query", "code") .endObject().startObject("options").endObject().endObject().endObject().string(); String code; @@ -308,7 +309,7 @@ public void testSourceParsingErrors() throws Exception { // check for missing lang parameter when parsing a script try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { - builder.startObject().field("script").startObject().field("code", "code").endObject().endObject(); + builder.startObject().field("script").startObject().field("source", "code").endObject().endObject(); IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON)); @@ -326,7 +327,7 @@ public void testSourceParsingErrors() throws Exception { // check for illegal options parameter when parsing a script try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { - builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code") + builder.startObject().field("script").startObject().field("lang", "lang").field("source", "code") .startObject("options").field("option", "option").endObject().endObject().endObject(); IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> diff --git a/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/30_single_value_field.yml b/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/30_single_value_field.yml index f5ad9c974005b..782e5d5ebbc4a 100644 --- a/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/30_single_value_field.yml +++ b/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/30_single_value_field.yml @@ -184,7 +184,7 @@ setup: search: index: test type: test - body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2"], "script" : { "my_script" : {"inline" : "1 + doc['val1'].value", "lang" : "js"} } } } } } + body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2"], "script" : { "my_script" : {"source" : "1 + doc['val1'].value", "lang" : "js"} } } } } } --- "With script params": @@ -194,4 +194,4 @@ setup: search: index: test type: test - body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"], "script" : { "my_script" : {"inline" : "my_var + doc['val1'].value", "params" : { "my_var" : 1 }, "lang" : "js" } } } } } } + body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"], "script" : { "my_script" : {"source" : "my_var + doc['val1'].value", "params" : { "my_var" : 1 }, "lang" : "js" } } } } } } diff --git a/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/40_multi_value_field.yml b/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/40_multi_value_field.yml index 87b30400c836d..b4abf41a515e9 100644 --- a/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/40_multi_value_field.yml +++ b/modules/aggs-matrix-stats/src/test/resources/rest-api-spec/test/stats/40_multi_value_field.yml @@ -199,7 +199,7 @@ setup: search: index: test type: test - body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["vals", "val3"], "script" : { "my_script" : {"inline" : "1 + doc['val1'].value", "lang" : "js"} } } } } } + body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["vals", "val3"], "script" : { "my_script" : {"source" : "1 + doc['val1'].value", "lang" : "js"} } } } } } --- "With script params": @@ -209,4 +209,4 @@ setup: search: index: test type: test - body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val3", "vals"], "script" : { "my_script" : {"inline" : "my_var + doc['val1'].value", "params" : { "my_var" : 1 }, "lang" : "js" } } } } } } + body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val3", "vals"], "script" : { "my_script" : {"source" : "my_var + doc['val1'].value", "params" : { "my_var" : 1 }, "lang" : "js" } } } } } } diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java index 110b4bf30a0a4..e06a92f483b85 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java @@ -498,10 +498,10 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.startObject(); query.startObject("script"); if (randomBoolean()) { - query.field("script", "return true"); + query.field("source", "return true"); } else { query.startObject("script"); - query.field("inline", "return true"); + query.field("source", "return true"); query.endObject(); } query.endObject(); @@ -526,7 +526,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.field("script", "return true"); } else { query.startObject("script"); - query.field("inline", "return true"); + query.field("source", "return true"); query.endObject(); } query.endObject(); diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml index cc6ebac6e9568..d89395d4d1939 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/50_script_processor_using_painless.yml @@ -9,7 +9,7 @@ "processors": [ { "script" : { - "inline": "ctx.bytes_total = (ctx.bytes_in + ctx.bytes_out) * params.factor", + "source": "ctx.bytes_total = (ctx.bytes_in + ctx.bytes_out) * params.factor", "params": { "factor": 10 } @@ -98,13 +98,13 @@ "processors": [ { "script" : { - "inline": "invalid painless, hear me roar!" + "source": "invalid painless, hear me roar!" } } ] } - match: { error.header.processor_type: "script" } - - match: { error.header.property_name: "inline" } + - match: { error.header.property_name: "source" } - match: { error.type: "script_exception" } - match: { error.reason: "compile error" } From e57b4fc7d25ddf229784154e418f194da6b9ad34 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 15:33:37 -0700 Subject: [PATCH 7/9] fix percolator test --- .../elasticsearch/percolator/PercolatorFieldMapperTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java index e06a92f483b85..1285efb592c65 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java @@ -498,7 +498,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { query.startObject(); query.startObject("script"); if (randomBoolean()) { - query.field("source", "return true"); + query.field("script", "return true"); } else { query.startObject("script"); query.field("source", "return true"); From bad295910b9ac5fb92d0fdf43cb62e0ef44fa1f5 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 17:45:56 -0700 Subject: [PATCH 8/9] fix scoring example --- .../rest-api-spec/test/script_expert_scoring/20_score.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml b/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml index 1a0134b154b69..9347cb343a9ee 100644 --- a/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml +++ b/plugins/examples/script-expert-scoring/src/test/resources/rest-api-spec/test/script_expert_scoring/20_score.yml @@ -41,7 +41,7 @@ setup: functions: - script_score: script: - inline: "pure_df" + source: "pure_df" lang: "expert_scripts" params: field: "important_field" From 1c0accc91ddf9b84ed3befa07e89afd50d2645f0 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 8 Jun 2017 21:26:52 -0700 Subject: [PATCH 9/9] fix ingest error message --- .../java/org/elasticsearch/ingest/common/ScriptProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java index 55e12e382c650..f6b913fdfb7a7 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java @@ -134,7 +134,7 @@ public ScriptProcessor create(Map registry, String pr String scriptPropertyUsed; if (Strings.hasLength(source)) { script = new Script(INLINE, lang, source, (Map)params); - scriptPropertyUsed = "inline"; + scriptPropertyUsed = "source"; } else if (Strings.hasLength(id)) { script = new Script(STORED, lang, id, (Map)params); scriptPropertyUsed = "id";