From 71bb60d56ff5d1cb416b7152c49aebbf4ead7113 Mon Sep 17 00:00:00 2001 From: Mantas <marc.mantas@gmail.com> Date: Tue, 12 Jul 2016 14:42:38 +0300 Subject: [PATCH] added geo centroid aggregation --- src/Aggregation/GeoCentroidAggregation.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Aggregation/GeoCentroidAggregation.php diff --git a/src/Aggregation/GeoCentroidAggregation.php b/src/Aggregation/GeoCentroidAggregation.php new file mode 100644 index 0000000..51399c4 --- /dev/null +++ b/src/Aggregation/GeoCentroidAggregation.php @@ -0,0 +1,60 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchDSL\Aggregation; + +use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait; + +/** + * Class representing geo centroid aggregation. + * + * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geocentroid-aggregation.html + */ +class GeoCentroidAggregation extends AbstractAggregation +{ + use MetricTrait; + + /** + * Inner aggregations container init. + * + * @param string $name + * @param string $field + */ + public function __construct($name, $field = null) + { + parent::__construct($name); + + $this->setField($field); + } + + /** + * {@inheritdoc} + */ + public function getArray() + { + $data = []; + if ($this->getField()) { + $data['field'] = $this->getField(); + } else { + throw new \LogicException('Geo centroid aggregation must have a field set.'); + } + + return $data; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'geo_centroid'; + } +} -- GitLab