diff --git a/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java b/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java index 52a06db582966..b55f87efd6830 100644 --- a/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java +++ b/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java @@ -249,7 +249,12 @@ public static ScriptMetaData fromXContent(XContentParser parser) throws IOExcept source = StoredScriptSource.fromXContent(parser, true); if (exists == null) { - scripts.put(id, source); + // due to a bug (https://github.com/elastic/elasticsearch/issues/47593) + // scripts may have been retained during upgrade that include the old-style + // id of lang#id; these scripts are unreachable after 7.0, so they are dropped + if (id.contains("#") == false) { + scripts.put(id, source); + } } else if (exists.getLang().equals(source.getLang()) == false) { throw new IllegalArgumentException("illegal stored script, id [" + id + "] used for multiple scripts with " + "different languages [" + exists.getLang() + "] and [" + source.getLang() + "]; scripts using the old " + diff --git a/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java b/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java index 7a856ee13b9d3..fc0ebe3f23fd6 100644 --- a/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java +++ b/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.UncheckedIOException; +import java.util.Collections; public class ScriptMetaDataTests extends AbstractSerializingTestCase { @@ -168,6 +169,42 @@ public void testLoadEmptyScripts() throws IOException { assertWarnings("empty templates should no longer be used"); } + public void testOldStyleDropped() throws IOException { + XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent()); + + builder.startObject(); + { + builder.startObject("painless#test"); + { + builder.field("lang", "painless"); + builder.field("source", "code"); + } + builder.endObject(); + builder.startObject("lang#test"); + { + builder.field("lang", "test"); + builder.field("source", "code"); + } + builder.endObject(); + builder.startObject("test"); + { + builder.field("lang", "painless"); + builder.field("source", "code"); + } + builder.endObject(); + } + builder.endObject(); + + XContentParser parser = XContentType.JSON.xContent() + .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, + BytesReference.bytes(builder).streamInput()); + ScriptMetaData smd = ScriptMetaData.fromXContent(parser); + assertNull(smd.getStoredScript("painless#test")); + assertNull(smd.getStoredScript("lang#test")); + assertEquals(new StoredScriptSource("painless", "code", Collections.emptyMap()), smd.getStoredScript("test")); + assertEquals(1, smd.getStoredScripts().size()); + } + @Override protected boolean enableWarningsCheck() { return true;