Skip to content

Commit aef45fc

Browse files
committed
Merge branch 'fix/1.x-metrics-aggs-script-file-id' into 1.x
2 parents ece99e6 + b93355f commit aef45fc

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/Nest/DSL/Aggregations/MetricAggregationBaseDescriptor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public interface IMetricAggregator
1414
[JsonProperty("script")]
1515
string Script { get; set; }
1616

17+
[JsonProperty("script_id")]
18+
string ScriptId { get; set; }
19+
20+
[JsonProperty("script_file")]
21+
string ScriptFile { get; set; }
22+
1723
[JsonProperty("params")]
1824
IDictionary<string, object> Params { get; set; }
1925

@@ -26,6 +32,8 @@ public abstract class MetricAggregator : IMetricAggregator
2632
{
2733
public PropertyPathMarker Field { get; set; }
2834
public string Script { get; set; }
35+
public string ScriptId { get; set; }
36+
public string ScriptFile { get; set; }
2937
public IDictionary<string, object> Params { get; set; }
3038
public string Language { get; set; }
3139
}
@@ -40,6 +48,10 @@ public abstract class MetricAggregationBaseDescriptor<TMetricAggregation, T> : I
4048

4149
string IMetricAggregator.Script { get; set; }
4250

51+
string IMetricAggregator.ScriptId { get; set; }
52+
53+
string IMetricAggregator.ScriptFile { get; set; }
54+
4355
IDictionary<string, object> IMetricAggregator.Params { get; set; }
4456

4557
string IMetricAggregator.Language { get; set; }
@@ -62,6 +74,18 @@ public TMetricAggregation Script(string script)
6274
return (TMetricAggregation)this;
6375
}
6476

77+
public TMetricAggregation ScriptId(string script)
78+
{
79+
Self.ScriptId = script;
80+
return (TMetricAggregation)this;
81+
}
82+
83+
public TMetricAggregation ScriptFile(string script)
84+
{
85+
Self.ScriptId = script;
86+
return (TMetricAggregation)this;
87+
}
88+
6589
public TMetricAggregation Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramSelector)
6690
{
6791
Self.Params = paramSelector(new FluentDictionary<string, object>());

src/Tests/Nest.Tests.Integration/Aggregations/MetricAggregationTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,47 @@ public void Max()
9292
termBucket.Value.Should().HaveValue();
9393
}
9494

95+
[Test]
96+
[Ignore("script.inline: on must be set in elasticsearch.yml")]
97+
public void ScriptMax()
98+
{
99+
var results = this.Client.Search<ElasticsearchProject>(s => s
100+
.Size(0)
101+
.Aggregations(a => a
102+
.Max("value_agg", t => t.Script("doc['loc'].value"))
103+
)
104+
);
105+
results.IsValid.Should().BeTrue();
106+
var termBucket = results.Aggs.Max("value_agg");
107+
termBucket.Should().NotBeNull();
108+
termBucket.Value.Should().HaveValue();
109+
}
110+
111+
[Test]
112+
[Ignore("script.indexed: on must be set in elasticsearch.yml")]
113+
public void ScriptIdMax()
114+
{
115+
var scriptResponse = this.Client.PutScript(p => p
116+
.Script("doc['loc'].value")
117+
.Lang(ScriptLang.Groovy)
118+
.Id("loc-value")
119+
);
120+
121+
scriptResponse.IsValid.Should().BeTrue();
122+
123+
var results = this.Client.Search<ElasticsearchProject>(s => s
124+
.Size(0)
125+
.Aggregations(a => a
126+
.Max("value_agg", t => t.ScriptId("loc-value"))
127+
)
128+
);
129+
130+
results.IsValid.Should().BeTrue();
131+
var termBucket = results.Aggs.Max("value_agg");
132+
termBucket.Should().NotBeNull();
133+
termBucket.Value.Should().HaveValue();
134+
}
135+
95136
[Test]
96137
public void Sum()
97138
{

0 commit comments

Comments
 (0)