Skip to content

Commit 2f2a0e3

Browse files
Stuart Camrusscam
authored andcommitted
6.0 Script changes (#2951)
* 6.0 Script changes - Groovy, JavaScript, and Python languages removed The Groovy, JavaScript, and Python scripting languages were deprecated in elasticsearch 5.0 and have now been removed. Use painless instead. - lang can no longer be specified when using a stored script as part of a requestedit The lang variable can no longer be specified as part of a request that uses a stored script otherwise an error will occur. Note that a request using a stored script is different from a request that puts a stored script. The language of the script has already been stored as part of the cluster state and an id is sufficient to access all of the information necessary to execute a stored script. - lang can no longer be used when putting, getting, or deleting a stored scriptedit Stored scripts can no longer have the lang parameter specified as part of the url when performing PUT, GET, and DELETE actions on the _scripts/ path. All stored scripts must have a unique id as the namespace is only id now and no longer lang and id. - Convert PutScriptApi to integration test - Remove no longer supported languages from ScriptLang enum
1 parent 46a5933 commit 2f2a0e3

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed
Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
1-
using System.Collections.Generic;
2-
using Elasticsearch.Net;
1+
using Elasticsearch.Net;
32
using Newtonsoft.Json;
43

54
namespace Nest
65
{
6+
/// <summary>
7+
/// A Stored script
8+
/// </summary>
79
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
810
[JsonConverter(typeof(ReadAsTypeJsonConverter<StoredScript>))]
911
public interface IStoredScript
1012
{
13+
/// <summary>
14+
/// The script language
15+
/// </summary>
1116
[JsonProperty("lang")]
1217
string Lang { get; set; }
1318

19+
/// <summary>
20+
/// The script source
21+
/// </summary>
1422
[JsonProperty("source")]
1523
string Source { get; set; }
1624
}
25+
26+
/// <inheritdoc />
1727
public class StoredScript : IStoredScript
1828
{
1929
[JsonProperty("lang")]
2030
string IStoredScript.Lang { get; set; }
31+
2132
[JsonProperty("source")]
2233
string IStoredScript.Source { get; set; }
2334

2435
//used for deserialization
25-
internal StoredScript() { }
36+
internal StoredScript() {}
2637

38+
/// <summary>
39+
/// Instantiates a new instance of <see cref="StoredScript"/>
40+
/// </summary>
41+
/// <param name="lang">Script language</param>
42+
/// <param name="source">Script source</param>
2743
protected StoredScript(string lang, string source)
2844
{
29-
((IStoredScript) this).Lang = lang;
30-
((IStoredScript) this).Source = source;
45+
IStoredScript self = this;
46+
self.Lang = lang;
47+
self.Source = source;
3148
}
3249
}
3350

@@ -36,39 +53,28 @@ public class PainlessScript : StoredScript
3653
private static readonly string Lang = ScriptLang.Painless.GetStringValue();
3754
public PainlessScript(string source) : base(Lang, source) { }
3855
}
39-
public class GroovyScript : StoredScript
40-
{
41-
private static readonly string Lang = ScriptLang.Groovy.GetStringValue();
42-
public GroovyScript(string source) : base(Lang, source) { }
43-
}
44-
public class JavaScriptScript : StoredScript
45-
{
46-
private static readonly string Lang = ScriptLang.JS.GetStringValue();
47-
public JavaScriptScript(string source) : base(Lang, source) { }
48-
}
49-
public class PythonScript : StoredScript
50-
{
51-
private static readonly string Lang = ScriptLang.Python.GetStringValue();
52-
public PythonScript(string source) : base(Lang, source) { }
53-
}
56+
5457
public class LuceneExpressionScript : StoredScript
5558
{
5659
private static readonly string Lang = ScriptLang.Expression.GetStringValue();
5760
public LuceneExpressionScript(string source) : base(Lang, source) { }
5861
}
62+
5963
public class MustacheScript : StoredScript
6064
{
6165
private static readonly string Lang = ScriptLang.Mustache.GetStringValue();
62-
public MustacheScript(string source) : base(Lang, source) { }
66+
public MustacheScript(string source) : base(Lang, source) { }
6367
}
6468

6569
public class StoredScriptDescriptor : DescriptorBase<StoredScriptDescriptor, IStoredScript>, IStoredScript
6670
{
67-
string IStoredScript.Lang { get; set; }
6871
string IStoredScript.Source { get; set; }
72+
string IStoredScript.Lang { get; set; }
73+
74+
public StoredScriptDescriptor Source(string source) => Assign(a => a.Source = source);
6975

7076
public StoredScriptDescriptor Lang(string lang) => Assign(a => a.Lang = lang);
7177

72-
public StoredScriptDescriptor Source(string source) => Assign(a => a.Source = source);
78+
public StoredScriptDescriptor Lang(ScriptLang lang) => Assign(a => a.Lang = lang.GetStringValue());
7379
}
7480
}

src/Nest/Modules/Scripting/PutScript/PutScriptRequest.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ public partial class PutScriptDescriptor
2222
public PutScriptDescriptor Script(Func<StoredScriptDescriptor, IStoredScript> selector) =>
2323
Assign(a => a.Script = selector?.Invoke(new StoredScriptDescriptor()));
2424

25+
/// <summary>
26+
/// A Painless language script
27+
/// </summary>
2528
public PutScriptDescriptor Painless(string source) => Assign(a => a.Script = new PainlessScript(source));
26-
public PutScriptDescriptor Groovy(string source) => Assign(a => a.Script = new GroovyScript(source));
27-
public PutScriptDescriptor JavaScript(string source) => Assign(a => a.Script = new JavaScriptScript(source));
28-
public PutScriptDescriptor Python(string source) => Assign(a => a.Script = new PythonScript(source));
29+
30+
/// <summary>
31+
/// A Lucene expression language script
32+
/// </summary>
2933
public PutScriptDescriptor LuceneExpression(string source) => Assign(a => a.Script = new LuceneExpressionScript(source));
34+
35+
/// <summary>
36+
/// A Mustache template language script
37+
/// </summary>
3038
public PutScriptDescriptor Mustache(string source) => Assign(a => a.Script = new MustacheScript(source));
3139
}
3240
}

src/Nest/Modules/Scripting/ScriptLang.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ public enum ScriptLang
1010
[EnumMember(Value = "painless")]
1111
Painless,
1212

13-
[EnumMember(Value = "groovy")]
14-
Groovy,
15-
16-
[EnumMember(Value = "js")]
17-
JS,
18-
19-
[EnumMember(Value = "python")]
20-
Python,
21-
2213
[EnumMember(Value = "expression")]
2314
Expression,
2415

src/Tests/Modules/Scripting/PutScript/PutScriptApiTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Elasticsearch.Net;
3+
using FluentAssertions;
34
using Nest;
45
using Tests.Framework;
56
using Tests.Framework.Integration;
@@ -9,13 +10,12 @@
910
namespace Tests.Modules.Scripting.PutScript
1011
{
1112
public class PutScriptApiTests
12-
: ApiTestBase<ReadOnlyCluster, IPutScriptResponse, IPutScriptRequest, PutScriptDescriptor, PutScriptRequest>
13+
: ApiIntegrationTestBase<ReadOnlyCluster, IPutScriptResponse, IPutScriptRequest, PutScriptDescriptor, PutScriptRequest>
1314
{
1415
public PutScriptApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1516

1617
private static readonly string _name = "scrpt1";
1718

18-
1919
protected override LazyResponses ClientUsage() => Calls(
2020
fluent: (client, f) => client.PutScript(_name, f),
2121
fluentAsync: (client, f) => client.PutScriptAsync(_name, f),
@@ -25,12 +25,18 @@ protected override LazyResponses ClientUsage() => Calls(
2525

2626
protected override HttpMethod HttpMethod => HttpMethod.PUT;
2727
protected override string UrlPath => $"/_scripts/{_name}";
28+
protected override int ExpectStatusCode => 200;
29+
protected override bool ExpectIsValid => true;
2830

2931
protected override bool SupportsDeserialization => false;
3032

31-
protected override object ExpectJson { get; } = new
33+
protected override object ExpectJson => new
3234
{
33-
script = new { lang = "painless", source = "1+1" }
35+
script = new
36+
{
37+
lang = "painless",
38+
source = "1+1"
39+
}
3440
};
3541

3642
protected override PutScriptDescriptor NewDescriptor() => new PutScriptDescriptor(_name);
@@ -42,5 +48,11 @@ protected override LazyResponses ClientUsage() => Calls(
4248
{
4349
Script = new PainlessScript("1+1")
4450
};
51+
52+
protected override void ExpectResponse(IPutScriptResponse response)
53+
{
54+
response.ShouldBeValid();
55+
response.Acknowledged.Should().BeTrue();
56+
}
4557
}
4658
}

0 commit comments

Comments
 (0)