Skip to content

Commit 0defcd5

Browse files
authored
implement IPercentageScoreHeuristic on PercentageScoreHeuristic (#4574)
This commit implements IPercentageScoreHeuristic on PercentageScoreHeuristic in order to fix an exception when attempting to serialize PercentageScore on SignificantTerms aggregation. Fixes #4573
1 parent 5dd9b21 commit 0defcd5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/PercentageScoreHeuristic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Nest
66
[ReadAs(typeof(PercentageScoreHeuristic))]
77
public interface IPercentageScoreHeuristic { }
88

9-
public class PercentageScoreHeuristic { }
9+
public class PercentageScoreHeuristic : IPercentageScoreHeuristic { }
1010

1111
public class PercentageScoreHeuristicDescriptor
1212
: DescriptorBase<PercentageScoreHeuristicDescriptor, IPercentageScoreHeuristic>, IPercentageScoreHeuristic { }
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Text;
3+
using Elastic.Xunit.XunitPlumbing;
4+
using FluentAssertions;
5+
using Nest;
6+
using Tests.Core.Client;
7+
8+
namespace Tests.Reproduce
9+
{
10+
public class GitHubIssue4573
11+
{
12+
[U]
13+
public void SerializePercentageScore()
14+
{
15+
Func<ISearchResponse<object>> action = () => TestClient.DefaultInMemoryClient.Search<object>(b => b
16+
.Aggregations(a => a
17+
.SignificantTerms("related_organisations", sigTerms => sigTerms
18+
.Field("organisations.keyword")
19+
.Size(10)
20+
.PercentageScore(p => p)
21+
.MinimumDocumentCount(5)
22+
)
23+
)
24+
);
25+
26+
action.Should().NotThrow();
27+
28+
var response = action();
29+
30+
var json = Encoding.UTF8.GetString(response.ApiCall.RequestBodyInBytes);
31+
json.Should().Contain("\"percentage\":{}");
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)