diff --git a/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/aggs/Metric.kt b/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/aggs/Metric.kt index 709afb9de5..234076b51c 100644 --- a/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/aggs/Metric.kt +++ b/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/aggs/Metric.kt @@ -130,10 +130,9 @@ data class PercentileAggResult(val values: Map) : AggregationRes } } -@Suppress("MagicNumber") data class PercentilesAgg( val field: FieldOperations<*>, - val percents: List = listOf(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0), + val percents: List? = null, ) : MetricAggregation() { override fun processResult(obj: Deserializer.ObjectCtx): PercentileAggResult { return PercentileAggResult(obj) @@ -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) + } } } } diff --git a/elasticmagic/src/commonTest/kotlin/dev/evo/elasticmagic/aggs/MetricTests.kt b/elasticmagic/src/commonTest/kotlin/dev/evo/elasticmagic/aggs/MetricTests.kt index c6559152f2..74bd263788 100644 --- a/elasticmagic/src/commonTest/kotlin/dev/evo/elasticmagic/aggs/MetricTests.kt +++ b/elasticmagic/src/commonTest/kotlin/dev/evo/elasticmagic/aggs/MetricTests.kt @@ -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" ) )