Skip to content

Commit

Permalink
Change PercentilesAgg parameters
Browse files Browse the repository at this point in the history
percents can be nullable
  • Loading branch information
a.usenko authored and anti-social committed Dec 28, 2023
1 parent 94738b9 commit 622c7d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ data class PercentileAggResult(val values: Map<Double, Double>) : AggregationRes
}
}

@Suppress("MagicNumber")
data class PercentilesAgg(
val field: FieldOperations<*>,
val percents: List<Double> = listOf(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0),
val percents: List<Double>? = null,
) : MetricAggregation<PercentileAggResult>() {
override fun processResult(obj: Deserializer.ObjectCtx): PercentileAggResult {
return PercentileAggResult(obj)
Expand All @@ -144,9 +143,11 @@ data class PercentilesAgg(

override fun visit(ctx: Serializer.ObjectCtx, compiler: BaseSearchQueryCompiler) {
ctx.field("field", field.getQualifiedFieldName())
ctx.array("percents") {
percents.forEach {
value(it)
if (percents != null) {
ctx.array("percents") {
percents.forEach {
value(it)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class MetricTests : TestAggregation() {
)
ratingAgg.compile() shouldContainExactly mapOf(
"percentiles" to mapOf(
"field" to "rating",
"percents" to listOf(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0),
"field" to "rating"
)
)

Expand Down

0 comments on commit 622c7d3

Please sign in to comment.