Skip to content

Commit 0772ae5

Browse files
committed
Correctly handle terms include/exclude
for Terms aggregation - Remove flags property as it's no longer supported and a regular expression pattern is sent as a string value against the "include" key - exact values are sent as an array of strings - Split TermsIncludeExclude out into separate types for "include" and "exclude"; Partitions and Number of partitions only available on include for Significant Terms aggregation - Remove dictionary that was incorrectly used to filter terms. Introduce a SignificantTermsIncludeExclude type to represent the available options. Add unit and integration tests for include and exclude filtering Fixes elastic#2682 Fixes elastic#2676 (cherry picked from commit a309d38)
1 parent 0c30c4e commit 0772ae5

File tree

17 files changed

+1208
-194
lines changed

17 files changed

+1208
-194
lines changed

docs/aggregations/bucket/significant-terms/significant-terms-aggregation-usage.asciidoc

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ please modify the original csharp file found at the link and submit the PR with
1515
[[significant-terms-aggregation-usage]]
1616
== Significant Terms Aggregation Usage
1717

18+
An aggregation that returns interesting or unusual occurrences of terms in a set.
19+
20+
[WARNING]
21+
--
22+
The significant_terms aggregation can be very heavy when run on large indices. Work is in progress
23+
to provide more lightweight sampling techniques.
24+
As a result, the API for this feature may change in non-backwards compatible ways
25+
26+
--
27+
28+
See the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-significantterms-aggregation.html[significant terms aggregation] for more detail.
29+
1830
=== Fluent DSL Example
1931

2032
[source,csharp]
@@ -80,3 +92,153 @@ sigNames.Should().NotBeNull();
8092
sigNames.DocCount.Should().BeGreaterThan(0);
8193
----
8294

95+
[[significant-terms-pattern-filter]]
96+
[float]
97+
== Filtering with a regular expression pattern
98+
99+
Using significant terms aggregation with filtering to include values using a regular expression pattern
100+
101+
=== Fluent DSL Example
102+
103+
[source,csharp]
104+
----
105+
s => s
106+
.Aggregations(a => a
107+
.SignificantTerms("significant_names", st => st
108+
.Field(p => p.Name)
109+
.MinimumDocumentCount(10)
110+
.MutualInformation(mi => mi
111+
.BackgroundIsSuperSet()
112+
.IncludeNegatives()
113+
)
114+
.Include("pi*")
115+
)
116+
)
117+
----
118+
119+
=== Object Initializer Syntax Example
120+
121+
[source,csharp]
122+
----
123+
new SearchRequest<Project>
124+
{
125+
Aggregations = new SignificantTermsAggregation("significant_names")
126+
{
127+
Field = Field<Project>(p => p.Name),
128+
MinimumDocumentCount = 10,
129+
MutualInformation = new MutualInformationHeuristic
130+
{
131+
BackgroundIsSuperSet = true,
132+
IncludeNegatives = true
133+
},
134+
Include = new SignificantTermsIncludeExclude("pi*")
135+
}
136+
}
137+
----
138+
139+
[source,javascript]
140+
.Example json output
141+
----
142+
{
143+
"aggs": {
144+
"significant_names": {
145+
"significant_terms": {
146+
"field": "name",
147+
"min_doc_count": 10,
148+
"mutual_information": {
149+
"background_is_superset": true,
150+
"include_negatives": true
151+
},
152+
"include": "pi*"
153+
}
154+
}
155+
}
156+
}
157+
----
158+
159+
=== Handling Responses
160+
161+
[source,csharp]
162+
----
163+
response.ShouldBeValid();
164+
var sigNames = response.Aggs.SignificantTerms("significant_names");
165+
sigNames.Should().NotBeNull();
166+
sigNames.DocCount.Should().BeGreaterThan(0);
167+
----
168+
169+
[[significant-terms-exact-value-filter]]
170+
[float]
171+
== Filtering with exact values
172+
173+
Using significant terms aggregation with filtering to exclude specific values
174+
175+
=== Fluent DSL Example
176+
177+
[source,csharp]
178+
----
179+
s => s
180+
.Aggregations(a => a
181+
.SignificantTerms("significant_names", st => st
182+
.Field(p => p.Name)
183+
.MinimumDocumentCount(10)
184+
.MutualInformation(mi => mi
185+
.BackgroundIsSuperSet()
186+
.IncludeNegatives()
187+
)
188+
.Exclude(new [] { "pierce" })
189+
)
190+
)
191+
----
192+
193+
=== Object Initializer Syntax Example
194+
195+
[source,csharp]
196+
----
197+
new SearchRequest<Project>
198+
{
199+
Aggregations = new SignificantTermsAggregation("significant_names")
200+
{
201+
Field = Field<Project>(p => p.Name),
202+
MinimumDocumentCount = 10,
203+
MutualInformation = new MutualInformationHeuristic
204+
{
205+
BackgroundIsSuperSet = true,
206+
IncludeNegatives = true
207+
},
208+
Exclude = new SignificantTermsIncludeExclude(new[] { "pierce" })
209+
}
210+
}
211+
----
212+
213+
[source,javascript]
214+
.Example json output
215+
----
216+
{
217+
"aggs": {
218+
"significant_names": {
219+
"significant_terms": {
220+
"field": "name",
221+
"min_doc_count": 10,
222+
"mutual_information": {
223+
"background_is_superset": true,
224+
"include_negatives": true
225+
},
226+
"exclude": [
227+
"pierce"
228+
]
229+
}
230+
}
231+
}
232+
}
233+
----
234+
235+
=== Handling Responses
236+
237+
[source,csharp]
238+
----
239+
response.ShouldBeValid();
240+
var sigNames = response.Aggs.SignificantTerms("significant_names");
241+
sigNames.Should().NotBeNull();
242+
sigNames.DocCount.Should().BeGreaterThan(0);
243+
----
244+

0 commit comments

Comments
 (0)