Skip to content

Commit f76f695

Browse files
committed
Merge pull request #1368 from elastic/feature/sig-terms-heuristics
Add percentage and scripted heuristics to significant terms
2 parents 1ecf2ab + 721ae31 commit f76f695

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Nest/DSL/Aggregations/SignificantTermsAggregationDescriptor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public interface ISignificantTermsAggregator : IBucketAggregator
4040
[JsonProperty("gnd")]
4141
GoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; }
4242

43+
[JsonProperty("percentage")]
44+
PercentageScoreHeuristic PercentageScore { get; set; }
45+
46+
[JsonProperty("script_heuristic")]
47+
ScriptedHeuristic Script { get; set; }
48+
4349
[JsonProperty("background_filter")]
4450
IFilterContainer BackgroundFilter { get; set; }
4551

@@ -57,6 +63,8 @@ public class SignificantTermsAggregator : BucketAggregator, ISignificantTermsAgg
5763
public MutualInformationHeuristic MutualInformation { get; set; }
5864
public ChiSquareHeuristic ChiSquare { get; set; }
5965
public GoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; }
66+
public PercentageScoreHeuristic PercentageScore { get; set; }
67+
public ScriptedHeuristic Script { get; set; }
6068
public IFilterContainer BackgroundFilter { get; set; }
6169
}
6270

@@ -84,6 +92,10 @@ public class SignificantTermsAggregationDescriptor<T> : BucketAggregationBaseDes
8492

8593
GoogleNormalizedDistanceHeuristic ISignificantTermsAggregator.GoogleNormalizedDistance { get; set; }
8694

95+
PercentageScoreHeuristic ISignificantTermsAggregator.PercentageScore { get; set; }
96+
97+
ScriptedHeuristic ISignificantTermsAggregator.Script { get; set; }
98+
8799
IFilterContainer ISignificantTermsAggregator.BackgroundFilter { get; set; }
88100

89101
public SignificantTermsAggregationDescriptor<T> Field(string field)
@@ -167,6 +179,18 @@ public SignificantTermsAggregationDescriptor<T> GoogleNormalizedDistance(bool? b
167179
return this;
168180
}
169181

182+
public SignificantTermsAggregationDescriptor<T> PercentageScore()
183+
{
184+
this.Self.PercentageScore = new PercentageScoreHeuristic();
185+
return this;
186+
}
187+
188+
public SignificantTermsAggregationDescriptor<T> Script(Func<ScriptedHeuristicDescriptor, ScriptedHeuristicDescriptor> scriptSelector)
189+
{
190+
this.Self.Script = scriptSelector(new ScriptedHeuristicDescriptor()).ScriptedHeuristic;
191+
return this;
192+
}
193+
170194
public SignificantTermsAggregationDescriptor<T> BackgroundFilter(Func<FilterDescriptor<T>, FilterContainer> selector)
171195
{
172196
this.Self.BackgroundFilter = selector(new FilterDescriptor<T>());

src/Nest/Domain/Aggregations/ISignificantTermsHeuristic.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Newtonsoft.Json;
3+
using System;
34

45
namespace Nest
56
{
@@ -25,4 +26,39 @@ public class GoogleNormalizedDistanceHeuristic
2526
public bool? BackgroundIsSuperSet { get; set; }
2627
}
2728

29+
public class PercentageScoreHeuristic
30+
{
31+
}
32+
33+
public class ScriptedHeuristic
34+
{
35+
[JsonProperty("script")]
36+
public string Script { get; set; }
37+
[JsonProperty("lang")]
38+
public string Lang { get; set; }
39+
[JsonProperty("params")]
40+
public IDictionary<string, object> Params { get; set; }
41+
}
42+
43+
public class ScriptedHeuristicDescriptor
44+
{
45+
internal ScriptedHeuristic ScriptedHeuristic = new ScriptedHeuristic();
46+
public ScriptedHeuristicDescriptor Script(string script)
47+
{
48+
this.ScriptedHeuristic.Script = script;
49+
return this;
50+
}
51+
52+
public ScriptedHeuristicDescriptor Lang(string lang)
53+
{
54+
this.ScriptedHeuristic.Lang = lang;
55+
return this;
56+
}
57+
58+
public ScriptedHeuristicDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsSelector)
59+
{
60+
this.ScriptedHeuristic.Params = paramsSelector(new FluentDictionary<string, object>());
61+
return this;
62+
}
63+
}
2864
}

0 commit comments

Comments
 (0)