Skip to content

Commit eccab30

Browse files
author
Stuart Cam
authored
DFI similarity type only exists on 2.3.0+ versions. Fix tests. Update docs. (#3052)
1 parent 946d259 commit eccab30

File tree

3 files changed

+96
-20
lines changed

3 files changed

+96
-20
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ An aggregation that returns interesting or unusual occurrences of terms in a set
2121

2222
[WARNING]
2323
--
24-
The significant_terms aggregation can be very heavy when run on large indices. Work is in progress
25-
to provide more lightweight sampling techniques.
24+
The significant_terms aggregation can be very heavy when run on large indices. Work is in progress
25+
to provide more lightweight sampling techniques.
2626
As a result, the API for this feature may change in non-backwards compatible ways
2727

2828
--
@@ -37,7 +37,7 @@ s => s
3737
.Aggregations(a => a
3838
.SignificantTerms("significant_names", st => st
3939
.Field(p => p.Name)
40-
.MinimumDocumentCount(10)
40+
.MinimumDocumentCountAsLong(10)
4141
.MutualInformation(mi => mi
4242
.BackgroundIsSuperSet()
4343
.IncludeNegatives()
@@ -55,7 +55,7 @@ new SearchRequest<Project>
5555
Aggregations = new SignificantTermsAggregation("significant_names")
5656
{
5757
Field = Field<Project>(p => p.Name),
58-
MinimumDocumentCount = 10,
58+
MinimumDocumentCountAsLong = 10,
5959
MutualInformation = new MutualInformationHeuristic
6060
{
6161
BackgroundIsSuperSet = true,
@@ -108,7 +108,7 @@ s => s
108108
.Aggregations(a => a
109109
.SignificantTerms("significant_names", st => st
110110
.Field(p => p.Name)
111-
.MinimumDocumentCount(10)
111+
.MinimumDocumentCountAsLong(10)
112112
.MutualInformation(mi => mi
113113
.BackgroundIsSuperSet()
114114
.IncludeNegatives()
@@ -127,7 +127,7 @@ new SearchRequest<Project>
127127
Aggregations = new SignificantTermsAggregation("significant_names")
128128
{
129129
Field = Field<Project>(p => p.Name),
130-
MinimumDocumentCount = 10,
130+
MinimumDocumentCountAsLong = 10,
131131
MutualInformation = new MutualInformationHeuristic
132132
{
133133
BackgroundIsSuperSet = true,
@@ -182,7 +182,7 @@ s => s
182182
.Aggregations(a => a
183183
.SignificantTerms("significant_names", st => st
184184
.Field(p => p.Name)
185-
.MinimumDocumentCount(10)
185+
.MinimumDocumentCountAsLong(10)
186186
.MutualInformation(mi => mi
187187
.BackgroundIsSuperSet()
188188
.IncludeNegatives()
@@ -201,7 +201,7 @@ new SearchRequest<Project>
201201
Aggregations = new SignificantTermsAggregation("significant_names")
202202
{
203203
Field = Field<Project>(p => p.Name),
204-
MinimumDocumentCount = 10,
204+
MinimumDocumentCountAsLong = 10,
205205
MutualInformation = new MutualInformationHeuristic
206206
{
207207
BackgroundIsSuperSet = true,

docs/aggregations/metric/top-hits/top-hits-aggregation-usage.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ s => s
3535
.Script(ss => ss
3636
.Type("number")
3737
.Script(sss => sss
38-
.Inline("Math.sin(34*(double)doc['numberOfCommits'].value)")
38+
.Inline("sin(doc['numberOfCommits'].value)")
3939
.Lang("groovy")
4040
)
4141
.Order(SortOrder.Descending)
@@ -91,7 +91,7 @@ new SearchRequest<Project>
9191
new ScriptSort
9292
{
9393
Type = "number",
94-
Script = new InlineScript("Math.sin(34*(double)doc['numberOfCommits'].value)") { Lang = "groovy" },
94+
Script = new InlineScript("sin(doc['numberOfCommits'].value)") { Lang = "groovy" },
9595
Order = SortOrder.Descending
9696
},
9797
},
@@ -144,7 +144,7 @@ new SearchRequest<Project>
144144
"type": "number",
145145
"script": {
146146
"lang": "groovy",
147-
"inline": "Math.sin(34*(double)doc['numberOfCommits'].value)"
147+
"inline": "sin(doc['numberOfCommits'].value)"
148148
},
149149
"order": "desc"
150150
}

src/Tests/Indices/IndexManagement/CreateIndex/CreateIndexApiTests.cs

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ protected override LazyResponses ClientUsage() => Calls(
9494
.Default("tfidf", c => c
9595
.DiscountOverlaps()
9696
)
97-
.DFI("dfi", df => df
98-
.IndependenceMeasure(DFIIndependenceMeasure.ChiSquared)
99-
)
10097
.DFR("dfr", df => df
10198
.AfterEffect(DFRAfterEffect.B)
10299
.BasicModel(DFRBasicModel.D)
@@ -136,11 +133,6 @@ protected override LazyResponses ClientUsage() => Calls(
136133
DiscountOverlaps = true
137134
}
138135
},
139-
{ "dfi", new DFISimilarity
140-
{
141-
IndependenceMeasure = DFIIndependenceMeasure.ChiSquared
142-
}
143-
},
144136
{ "dfr", new DFRSimilarity
145137
{
146138
AfterEffect = DFRAfterEffect.B,
@@ -190,11 +182,95 @@ protected override void ExpectResponse(ICreateIndexResponse response)
190182
similarities.Should().NotBeNull();
191183
similarities.Should().ContainKey("bm25").WhichValue.Should().BeOfType<BM25Similarity>();
192184
similarities.Should().ContainKey("tfidf").WhichValue.Should().BeOfType<DefaultSimilarity>();
193-
similarities.Should().ContainKey("dfi").WhichValue.Should().BeOfType<DFISimilarity>();
194185
similarities.Should().ContainKey("dfr").WhichValue.Should().BeOfType<DFRSimilarity>();
195186
similarities.Should().ContainKey("ib").WhichValue.Should().BeOfType<IBSimilarity>();
196187
similarities.Should().ContainKey("lmd").WhichValue.Should().BeOfType<LMDirichletSimilarity>();
197188
similarities.Should().ContainKey("lmj").WhichValue.Should().BeOfType<LMJelinekMercerSimilarity>();
198189
}
199190
}
191+
192+
[SkipVersion("<2.3.0", "DFI Not supported prior to 2.3.0")]
193+
public class CreateIndexDFIApiTests : ApiIntegrationTestBase<WritableCluster, ICreateIndexResponse, ICreateIndexRequest, CreateIndexDescriptor, CreateIndexRequest>
194+
{
195+
public CreateIndexDFIApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
196+
protected override LazyResponses ClientUsage() => Calls(
197+
fluent: (client, f) => client.CreateIndex(CallIsolatedValue, f),
198+
fluentAsync: (client, f) => client.CreateIndexAsync(CallIsolatedValue, f),
199+
request: (client, r) => client.CreateIndex(r),
200+
requestAsync: (client, r) => client.CreateIndexAsync(r)
201+
);
202+
203+
protected override bool ExpectIsValid => true;
204+
protected override int ExpectStatusCode => 200;
205+
protected override HttpMethod HttpMethod => HttpMethod.PUT;
206+
protected override string UrlPath => $"/{CallIsolatedValue}";
207+
208+
protected override object ExpectJson { get; } = new
209+
{
210+
settings = new Dictionary<string, object>
211+
{
212+
{ "index.number_of_replicas", 1 },
213+
{ "index.number_of_shards", 1 },
214+
{ "similarity", new
215+
{
216+
dfi = new
217+
{
218+
independence_measure = "chisquared",
219+
type = "DFI"
220+
}
221+
}
222+
}
223+
}
224+
};
225+
226+
protected override CreateIndexDescriptor NewDescriptor() => new CreateIndexDescriptor(CallIsolatedValue);
227+
228+
protected override Func<CreateIndexDescriptor, ICreateIndexRequest> Fluent => d => d
229+
.Settings(s => s
230+
.NumberOfReplicas(1)
231+
.NumberOfShards(1)
232+
.Similarity(si => si
233+
.DFI("dfi", df => df
234+
.IndependenceMeasure(DFIIndependenceMeasure.ChiSquared)
235+
)
236+
)
237+
);
238+
239+
protected override CreateIndexRequest Initializer => new CreateIndexRequest(CallIsolatedValue)
240+
{
241+
Settings = new Nest.IndexSettings()
242+
{
243+
NumberOfReplicas = 1,
244+
NumberOfShards = 1,
245+
Similarity = new Similarities
246+
{
247+
{ "dfi", new DFISimilarity
248+
{
249+
IndependenceMeasure = DFIIndependenceMeasure.ChiSquared
250+
}
251+
}
252+
}
253+
}
254+
};
255+
256+
protected override void ExpectResponse(ICreateIndexResponse response)
257+
{
258+
response.ShouldBeValid();
259+
response.Acknowledged.Should().BeTrue();
260+
261+
var indexSettings = this.Client.GetIndexSettings(g => g.Index(CallIsolatedValue));
262+
263+
indexSettings.ShouldBeValid();
264+
indexSettings.Indices.Should().NotBeEmpty().And.ContainKey(CallIsolatedValue);
265+
266+
var settings = indexSettings.Indices[CallIsolatedValue];
267+
268+
settings.Settings.NumberOfShards.Should().Be(1);
269+
settings.Settings.NumberOfReplicas.Should().Be(1);
270+
var similarities = settings.Settings.Similarity;
271+
272+
similarities.Should().NotBeNull();
273+
similarities.Should().ContainKey("dfi").WhichValue.Should().BeOfType<DFISimilarity>();
274+
}
275+
}
200276
}

0 commit comments

Comments
 (0)