Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for deprecated StoredScript contexts #31394

Merged
merged 5 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/reference/migration/migrate_7_0/api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ will be for such settings to be copied on such operations. To enable users in
`copy_settings` parameter was added on the REST layer. As this behavior will be
the only behavior in 8.0.0, this parameter is deprecated in 7.0.0 for removal in
8.0.0.

==== The deprecated stored script contexts have now been removed
When putting stored scripts, support for storing them with the deprecated `template` context or without a context is
now removed. Scripts must be stored using the `script` context as mentioned in the documentation.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -152,25 +151,22 @@ public void testTemplateQueryAsEscapedStringWithConditionalClauseAtEnd() throws
public void testIndexedTemplateClient() throws Exception {
assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("testTemplate")
.setContent(new BytesArray("{" +
"\"template\":{" +
" \"query\":{" +
" \"match\":{" +
" \"theField\" : \"{{fieldParam}}\"}" +
" }" +
"}" +
"}"), XContentType.JSON));


assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("testTemplate").setContent(new BytesArray("{" +
"\"template\":{" +
" \"query\":{" +
" \"match\":{" +
" \"theField\" : \"{{fieldParam}}\"}" +
" }" +
"}" +
"}"), XContentType.JSON));
.setContent(
new BytesArray(
"{" +
" \"script\": {" +
" \"lang\": \"mustache\"," +
" \"source\": {" +
" \"query\": {" +
" \"match\": {" +
" \"theField\": \"{{fieldParam}}\"" +
" }" +
" }" +
" }" +
" }" +
"}"
),
XContentType.JSON));

GetStoredScriptResponse getResponse = client().admin().cluster()
.prepareGetStoredScript("testTemplate").get();
Expand Down Expand Up @@ -198,41 +194,32 @@ public void testIndexedTemplateClient() throws Exception {

getResponse = client().admin().cluster().prepareGetStoredScript("testTemplate").get();
assertNull(getResponse.getSource());
assertWarnings("the template context is now deprecated. Specify templates in a \"script\" element.");
}

public void testIndexedTemplate() throws Exception {
assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("1a")
.setContent(new BytesArray("{" +
"\"template\":{" +
" \"query\":{" +
" \"match\":{" +
" \"theField\" : \"{{fieldParam}}\"}" +
" }" +
"}" +
"}"
), XContentType.JSON)

String script =
"{" +
" \"script\": {" +
" \"lang\": \"mustache\"," +
" \"source\": {" +
" \"query\": {" +
" \"match\": {" +
" \"theField\": \"{{fieldParam}}\"" +
" }" +
" }" +
" }" +
" }" +
"}";

assertAcked(
client().admin().cluster().preparePutStoredScript().setId("1a").setContent(new BytesArray(script), XContentType.JSON)
);
assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("2")
.setContent(new BytesArray("{" +
"\"template\":{" +
" \"query\":{" +
" \"match\":{" +
" \"theField\" : \"{{fieldParam}}\"}" +
" }" +
"}" +
"}"), XContentType.JSON)
assertAcked(
client().admin().cluster().preparePutStoredScript().setId("2").setContent(new BytesArray(script), XContentType.JSON)
);
assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("3")
.setContent(new BytesArray("{" +
"\"template\":{" +
" \"match\":{" +
" \"theField\" : \"{{fieldParam}}\"}" +
" }" +
"}"), XContentType.JSON)
assertAcked(
client().admin().cluster().preparePutStoredScript().setId("3").setContent(new BytesArray(script), XContentType.JSON)
);

BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
Expand Down Expand Up @@ -268,7 +255,6 @@ public void testIndexedTemplate() throws Exception {
.setScript("2").setScriptType(ScriptType.STORED).setScriptParams(templateParams)
.get();
assertHitCount(searchResponse.getResponse(), 1);
assertWarnings("the template context is now deprecated. Specify templates in a \"script\" element.");
}

// Relates to #10397
Expand All @@ -282,13 +268,27 @@ public void testIndexedTemplateOverwrite() throws Exception {
client().admin().indices().prepareRefresh().get();

int iterations = randomIntBetween(2, 11);
String query =
"{" +
" \"script\": {" +
" \"lang\": \"mustache\"," +
" \"source\": {" +
" \"query\": {" +
" \"match_phrase_prefix\": {" +
" \"searchtext\": {" +
" \"query\": \"{{P_Keyword1}}\"," +
" \"slop\": {{slop}}" +
" }" +
" }" +
" }" +
" }" +
" }" +
"}";
for (int i = 1; i < iterations; i++) {
assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("git01")
.setContent(new BytesArray(
"{\"template\":{\"query\": {\"match_phrase_prefix\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\","
+ "\"slop\": -1}}}}}"),
XContentType.JSON));
.setContent(new BytesArray(query.replace("{{slop}}", Integer.toString(-1))), XContentType.JSON)
);

GetStoredScriptResponse getResponse = client().admin().cluster().prepareGetStoredScript("git01").get();
assertNotNull(getResponse.getSource());
Expand All @@ -304,25 +304,39 @@ public void testIndexedTemplateOverwrite() throws Exception {

assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("git01")
.setContent(new BytesArray("{\"query\": {\"match_phrase_prefix\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\"," +
"\"slop\": 0}}}}"), XContentType.JSON));
.setContent(new BytesArray(query.replace("{{slop}}", Integer.toString(0))), XContentType.JSON)
);

SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client())
.setRequest(new SearchRequest("testindex").types("test"))
.setScript("git01").setScriptType(ScriptType.STORED).setScriptParams(templateParams)
.get();
assertHitCount(searchResponse.getResponse(), 1);
}
assertWarnings("the template context is now deprecated. Specify templates in a \"script\" element.");
}

public void testIndexedTemplateWithArray() throws Exception {
String multiQuery = "{\"query\":{\"terms\":{\"theField\":[\"{{#fieldParam}}\",\"{{.}}\",\"{{/fieldParam}}\"]}}}";
String multiQuery =
"{\n" +
" \"script\": {\n" +
" \"lang\": \"mustache\",\n" +
" \"source\": {\n" +
" \"query\": {\n" +
" \"terms\": {\n" +
" \"theField\": [\n" +
" \"{{#fieldParam}}\",\n" +
" \"{{.}}\",\n" +
" \"{{/fieldParam}}\"\n" +
" ]\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
assertAcked(
client().admin().cluster().preparePutStoredScript()
.setId("4")
.setContent(BytesReference.bytes(jsonBuilder().startObject().field("template", multiQuery).endObject()),
XContentType.JSON)
.setContent(new BytesArray(multiQuery), XContentType.JSON)
);
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
bulkRequestBuilder.add(client().prepareIndex("test", "type", "1").setSource("{\"theField\":\"foo\"}", XContentType.JSON));
Expand All @@ -342,7 +356,6 @@ public void testIndexedTemplateWithArray() throws Exception {
.setScript("4").setScriptType(ScriptType.STORED).setScriptParams(arrayTemplateParams)
.get();
assertHitCount(searchResponse.getResponse(), 5);
assertWarnings("the template context is now deprecated. Specify templates in a \"script\" element.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);

if (in.readBoolean()) {
if (in.getVersion().onOrAfter(Version.V_5_3_0)) {
source = new StoredScriptSource(in);
} else {
source = new StoredScriptSource(in.readString());
}
source = new StoredScriptSource(in);
} else {
source = null;
}
Expand All @@ -136,12 +132,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(false);
} else {
out.writeBoolean(true);

if (out.getVersion().onOrAfter(Version.V_5_3_0)) {
source.writeTo(out);
} else {
out.writeString(source.getSource());
}
source.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
out.writeString(id);
Expand Down
Loading