Skip to content
Snippets Groups Projects
Commit 6d9a5507 authored by Mantas's avatar Mantas
Browse files

added date histogram aggregation

parent 0745aebc
No related branches found
No related tags found
No related merge requests found
<?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\BucketingTrait;
/**
* Class representing Histogram aggregation.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
*/
class DateHistogramAggregation extends AbstractAggregation
{
use BucketingTrait;
/**
* @var string
*/
protected $interval;
/**
* Inner aggregations container init.
*
* @param string $name
* @param string $field
* @param string $interval
*/
public function __construct(
$name,
$field = null,
$interval = null
) {
parent::__construct($name);
$this->setField($field);
$this->setInterval($interval);
}
/**
* @return int
*/
public function getInterval()
{
return $this->interval;
}
/**
* @param string $interval
*/
public function setInterval($interval)
{
$this->interval = $interval;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'date_histogram';
}
/**
* {@inheritdoc}
*/
public function getArray()
{
if (!$this->getField() || !$this->getInterval()) {
throw new \LogicException('Date histogram aggregation must have field and interval set.');
}
$out = [
'field' => $this->getField(),
'interval' => $this->getInterval(),
];
$out = $this->processArray($out);
return $out;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment