Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ An aggregation that returns interesting or unusual occurrences of terms in a set

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

--
Expand All @@ -37,7 +37,7 @@ s => s
.Aggregations(a => a
.SignificantTerms("significant_names", st => st
.Field(p => p.Name)
.MinimumDocumentCount(10)
.MinimumDocumentCountAsLong(10)
.MutualInformation(mi => mi
.BackgroundIsSuperSet()
.IncludeNegatives()
Expand All @@ -55,7 +55,7 @@ new SearchRequest<Project>
Aggregations = new SignificantTermsAggregation("significant_names")
{
Field = Field<Project>(p => p.Name),
MinimumDocumentCount = 10,
MinimumDocumentCountAsLong = 10,
MutualInformation = new MutualInformationHeuristic
{
BackgroundIsSuperSet = true,
Expand Down Expand Up @@ -108,7 +108,7 @@ s => s
.Aggregations(a => a
.SignificantTerms("significant_names", st => st
.Field(p => p.Name)
.MinimumDocumentCount(10)
.MinimumDocumentCountAsLong(10)
.MutualInformation(mi => mi
.BackgroundIsSuperSet()
.IncludeNegatives()
Expand All @@ -127,7 +127,7 @@ new SearchRequest<Project>
Aggregations = new SignificantTermsAggregation("significant_names")
{
Field = Field<Project>(p => p.Name),
MinimumDocumentCount = 10,
MinimumDocumentCountAsLong = 10,
MutualInformation = new MutualInformationHeuristic
{
BackgroundIsSuperSet = true,
Expand Down Expand Up @@ -182,7 +182,7 @@ s => s
.Aggregations(a => a
.SignificantTerms("significant_names", st => st
.Field(p => p.Name)
.MinimumDocumentCount(10)
.MinimumDocumentCountAsLong(10)
.MutualInformation(mi => mi
.BackgroundIsSuperSet()
.IncludeNegatives()
Expand All @@ -201,7 +201,7 @@ new SearchRequest<Project>
Aggregations = new SignificantTermsAggregation("significant_names")
{
Field = Field<Project>(p => p.Name),
MinimumDocumentCount = 10,
MinimumDocumentCountAsLong = 10,
MutualInformation = new MutualInformationHeuristic
{
BackgroundIsSuperSet = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ s => s
.Script(ss => ss
.Type("number")
.Script(sss => sss
.Inline("Math.sin(34*(double)doc['numberOfCommits'].value)")
.Inline("sin(doc['numberOfCommits'].value)")
.Lang("groovy")
)
.Order(SortOrder.Descending)
Expand Down Expand Up @@ -91,7 +91,7 @@ new SearchRequest<Project>
new ScriptSort
{
Type = "number",
Script = new InlineScript("Math.sin(34*(double)doc['numberOfCommits'].value)") { Lang = "groovy" },
Script = new InlineScript("sin(doc['numberOfCommits'].value)") { Lang = "groovy" },
Order = SortOrder.Descending
},
},
Expand Down Expand Up @@ -144,7 +144,7 @@ new SearchRequest<Project>
"type": "number",
"script": {
"lang": "groovy",
"inline": "Math.sin(34*(double)doc['numberOfCommits'].value)"
"inline": "sin(doc['numberOfCommits'].value)"
},
"order": "desc"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ protected override LazyResponses ClientUsage() => Calls(
.Default("tfidf", c => c
.DiscountOverlaps()
)
.DFI("dfi", df => df
.IndependenceMeasure(DFIIndependenceMeasure.ChiSquared)
)
.DFR("dfr", df => df
.AfterEffect(DFRAfterEffect.B)
.BasicModel(DFRBasicModel.D)
Expand Down Expand Up @@ -136,11 +133,6 @@ protected override LazyResponses ClientUsage() => Calls(
DiscountOverlaps = true
}
},
{ "dfi", new DFISimilarity
{
IndependenceMeasure = DFIIndependenceMeasure.ChiSquared
}
},
{ "dfr", new DFRSimilarity
{
AfterEffect = DFRAfterEffect.B,
Expand Down Expand Up @@ -190,11 +182,95 @@ protected override void ExpectResponse(ICreateIndexResponse response)
similarities.Should().NotBeNull();
similarities.Should().ContainKey("bm25").WhichValue.Should().BeOfType<BM25Similarity>();
similarities.Should().ContainKey("tfidf").WhichValue.Should().BeOfType<DefaultSimilarity>();
similarities.Should().ContainKey("dfi").WhichValue.Should().BeOfType<DFISimilarity>();
similarities.Should().ContainKey("dfr").WhichValue.Should().BeOfType<DFRSimilarity>();
similarities.Should().ContainKey("ib").WhichValue.Should().BeOfType<IBSimilarity>();
similarities.Should().ContainKey("lmd").WhichValue.Should().BeOfType<LMDirichletSimilarity>();
similarities.Should().ContainKey("lmj").WhichValue.Should().BeOfType<LMJelinekMercerSimilarity>();
}
}

[SkipVersion("<2.3.0", "DFI Not supported prior to 2.3.0")]
public class CreateIndexDFIApiTests : ApiIntegrationTestBase<WritableCluster, ICreateIndexResponse, ICreateIndexRequest, CreateIndexDescriptor, CreateIndexRequest>
{
public CreateIndexDFIApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
protected override LazyResponses ClientUsage() => Calls(
fluent: (client, f) => client.CreateIndex(CallIsolatedValue, f),
fluentAsync: (client, f) => client.CreateIndexAsync(CallIsolatedValue, f),
request: (client, r) => client.CreateIndex(r),
requestAsync: (client, r) => client.CreateIndexAsync(r)
);

protected override bool ExpectIsValid => true;
protected override int ExpectStatusCode => 200;
protected override HttpMethod HttpMethod => HttpMethod.PUT;
protected override string UrlPath => $"/{CallIsolatedValue}";

protected override object ExpectJson { get; } = new
{
settings = new Dictionary<string, object>
{
{ "index.number_of_replicas", 1 },
{ "index.number_of_shards", 1 },
{ "similarity", new
{
dfi = new
{
independence_measure = "chisquared",
type = "DFI"
}
}
}
}
};

protected override CreateIndexDescriptor NewDescriptor() => new CreateIndexDescriptor(CallIsolatedValue);

protected override Func<CreateIndexDescriptor, ICreateIndexRequest> Fluent => d => d
.Settings(s => s
.NumberOfReplicas(1)
.NumberOfShards(1)
.Similarity(si => si
.DFI("dfi", df => df
.IndependenceMeasure(DFIIndependenceMeasure.ChiSquared)
)
)
);

protected override CreateIndexRequest Initializer => new CreateIndexRequest(CallIsolatedValue)
{
Settings = new Nest.IndexSettings()
{
NumberOfReplicas = 1,
NumberOfShards = 1,
Similarity = new Similarities
{
{ "dfi", new DFISimilarity
{
IndependenceMeasure = DFIIndependenceMeasure.ChiSquared
}
}
}
}
};

protected override void ExpectResponse(ICreateIndexResponse response)
{
response.ShouldBeValid();
response.Acknowledged.Should().BeTrue();

var indexSettings = this.Client.GetIndexSettings(g => g.Index(CallIsolatedValue));

indexSettings.ShouldBeValid();
indexSettings.Indices.Should().NotBeEmpty().And.ContainKey(CallIsolatedValue);

var settings = indexSettings.Indices[CallIsolatedValue];

settings.Settings.NumberOfShards.Should().Be(1);
settings.Settings.NumberOfReplicas.Should().Be(1);
var similarities = settings.Settings.Similarity;

similarities.Should().NotBeNull();
similarities.Should().ContainKey("dfi").WhichValue.Should().BeOfType<DFISimilarity>();
}
}
}