Skip to content

Commit 8a41c23

Browse files
committed
Add background_filter to significant terms aggregation
Closes #1178
1 parent b2dd6b7 commit 8a41c23

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: src/Nest/DSL/Aggregations/SignificantTermsAggregationDescriptor.cs

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public interface ISignificantTermsAggregator : IBucketAggregator
4040
[JsonProperty("gnd")]
4141
GoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; }
4242

43+
[JsonProperty("background_filter")]
44+
IFilterContainer BackgroundFilter { get; set; }
45+
4346
}
4447

4548
public class SignificantTermsAggregator : BucketAggregator, ISignificantTermsAggregator
@@ -54,6 +57,7 @@ public class SignificantTermsAggregator : BucketAggregator, ISignificantTermsAgg
5457
public MutualInformationHeuristic MutualInformation { get; set; }
5558
public ChiSquareHeuristic ChiSquare { get; set; }
5659
public GoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; }
60+
public IFilterContainer BackgroundFilter { get; set; }
5761
}
5862

5963
public class SignificantTermsAggregationDescriptor<T> : BucketAggregationBaseDescriptor<SignificantTermsAggregationDescriptor<T>, T>, ISignificantTermsAggregator where T : class
@@ -80,6 +84,8 @@ public class SignificantTermsAggregationDescriptor<T> : BucketAggregationBaseDes
8084

8185
GoogleNormalizedDistanceHeuristic ISignificantTermsAggregator.GoogleNormalizedDistance { get; set; }
8286

87+
IFilterContainer ISignificantTermsAggregator.BackgroundFilter { get; set; }
88+
8389
public SignificantTermsAggregationDescriptor<T> Field(string field)
8490
{
8591
Self.Field = field;
@@ -161,5 +167,10 @@ public SignificantTermsAggregationDescriptor<T> GoogleNormalizedDistance(bool? b
161167
return this;
162168
}
163169

170+
public SignificantTermsAggregationDescriptor<T> BackgroundFilter(Func<FilterDescriptor<T>, FilterContainer> selector)
171+
{
172+
this.Self.BackgroundFilter = selector(new FilterDescriptor<T>());
173+
return this;
174+
}
164175
}
165176
}

Diff for: src/Tests/Nest.Tests.Integration/Aggregations/BucketAggregationTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,27 @@ public void SignificantTerms()
6363
sigTermTerms.Items.Should().NotBeEmpty();
6464
}
6565
}
66+
}
6667

68+
[Test]
69+
public void SignificantTermsWithBackgroundFilter()
70+
{
71+
var results = this.Client.Search<ElasticsearchProject>(s => s
72+
.Size(0)
73+
.Aggregations(a => a
74+
.SignificantTerms("sig_terms", st => st
75+
.Field(p => p.Content)
76+
.BackgroundFilter(bf => bf
77+
.Term(p => p.Name, "elasticsearch")
78+
)
79+
)
80+
)
81+
);
82+
results.IsValid.Should().BeTrue();
83+
var bucket = results.Aggs.SignificantTerms("sig_terms");
84+
bucket.Items.Should().NotBeEmpty();
6785
}
86+
6887
[Test]
6988
public void Histogram()
7089
{

0 commit comments

Comments
 (0)