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

6.0 Script changes #2951

Merged
merged 3 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 3 additions & 40 deletions src/Nest/Modules/Scripting/IStoredScript.cs
Original file line number Diff line number Diff line change
@@ -1,74 +1,37 @@
using System.Collections.Generic;
using Elasticsearch.Net;
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeJsonConverter<StoredScript>))]
public interface IStoredScript
{
[JsonProperty("lang")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can still specify lang as part of the body, its just no longer part of the path in the url:

https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/script/StoredScriptSource.java#L157

string Lang { get; set; }

[JsonProperty("source")]
string Source { get; set; }
}
public class StoredScript : IStoredScript
{
[JsonProperty("lang")]
string IStoredScript.Lang { get; set; }
[JsonProperty("source")]
string IStoredScript.Source { get; set; }

//used for deserialization
internal StoredScript() { }

protected StoredScript(string lang, string source)
protected StoredScript(string source)
{
((IStoredScript) this).Lang = lang;
((IStoredScript) this).Source = source;
}
}

public class PainlessScript : StoredScript
{
private static readonly string Lang = ScriptLang.Painless.GetStringValue();
public PainlessScript(string source) : base(Lang, source) { }
}
public class GroovyScript : StoredScript
{
private static readonly string Lang = ScriptLang.Groovy.GetStringValue();
public GroovyScript(string source) : base(Lang, source) { }
}
public class JavaScriptScript : StoredScript
{
private static readonly string Lang = ScriptLang.JS.GetStringValue();
public JavaScriptScript(string source) : base(Lang, source) { }
}
public class PythonScript : StoredScript
{
private static readonly string Lang = ScriptLang.Python.GetStringValue();
public PythonScript(string source) : base(Lang, source) { }
}
public class LuceneExpressionScript : StoredScript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
private static readonly string Lang = ScriptLang.Expression.GetStringValue();
public LuceneExpressionScript(string source) : base(Lang, source) { }
}
public class MustacheScript : StoredScript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
private static readonly string Lang = ScriptLang.Mustache.GetStringValue();
public MustacheScript(string source) : base(Lang, source) { }
public PainlessScript(string source) : base(source) { }
}

public class StoredScriptDescriptor : DescriptorBase<StoredScriptDescriptor, IStoredScript>, IStoredScript
{
string IStoredScript.Lang { get; set; }
string IStoredScript.Source { get; set; }

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

public StoredScriptDescriptor Source(string source) => Assign(a => a.Source = source);
}
}
5 changes: 0 additions & 5 deletions src/Nest/Modules/Scripting/PutScript/PutScriptRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,5 @@ public PutScriptDescriptor Script(Func<StoredScriptDescriptor, IStoredScript> se
Assign(a => a.Script = selector?.Invoke(new StoredScriptDescriptor()));

public PutScriptDescriptor Painless(string source) => Assign(a => a.Script = new PainlessScript(source));
public PutScriptDescriptor Groovy(string source) => Assign(a => a.Script = new GroovyScript(source));
public PutScriptDescriptor JavaScript(string source) => Assign(a => a.Script = new JavaScriptScript(source));
public PutScriptDescriptor Python(string source) => Assign(a => a.Script = new PythonScript(source));
public PutScriptDescriptor LuceneExpression(string source) => Assign(a => a.Script = new LuceneExpressionScript(source));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep LuceneExpression and Mustache

public PutScriptDescriptor Mustache(string source) => Assign(a => a.Script = new MustacheScript(source));
}
}
2 changes: 1 addition & 1 deletion src/Tests/Modules/Scripting/PutScript/PutScriptApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override LazyResponses ClientUsage() => Calls(

protected override object ExpectJson { get; } = new
{
script = new { lang = "painless", source = "1+1" }
script = new { source = "1+1" }
};

protected override PutScriptDescriptor NewDescriptor() => new PutScriptDescriptor(_name);
Expand Down