diff --git a/src/Aggregation/StatsAggregation.php b/src/Aggregation/StatsAggregation.php new file mode 100644 index 0000000..8153032 --- /dev/null +++ b/src/Aggregation/StatsAggregation.php @@ -0,0 +1,16 @@ +setField('price'); + + $this->assertEquals([ + 'stats' => [ + 'field' => 'price', + ], + ], $query->build()); + } + + public function testItBuildTheAggregationUsingAScript(): void + { + $query = new StatsAggregation('price'); + $query->setScript('doc.price.value'); + + $this->assertEquals([ + 'stats' => [ + 'script' => [ + 'source' => 'doc.price.value', + ], + ], + ], $query->build()); + } + + public function testWithFieldName(): void + { + $query = new StatsAggregation('price'); + + $this->assertEquals([ + 'stats' => [ + 'field' => 'price', + ], + ], $query->build()); + } + + public function testItBuildTheAggregationWithMissingValue(): void + { + $query = new StatsAggregation('price', 'price'); + $query->setMissing(10); + + $this->assertEquals([ + 'stats' => [ + 'field' => 'price', + 'missing' => 10, + ], + ], $query->build()); + } +}