-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DateHistogramAggregation #66
base: main
Are you sure you want to change the base?
Conversation
public function __construct(string $name, string $field, string $calendarInterval) | ||
{ | ||
$this->name = $name; | ||
$this->field = $field; | ||
$this->calendarInterval = $calendarInterval; | ||
} | ||
|
||
public function payload(): array | ||
{ | ||
$parameters = [ | ||
'field' => $this->field, | ||
'calendar_interval' => $this->calendarInterval, | ||
]; | ||
|
||
return [ | ||
'date_histogram' => $parameters, | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used your suggestion in the application I'm working on, but I needed an aggregation in the histogram. See the suggestion for how I've implemented the aggregations.
public function __construct(string $name, string $field, string $calendarInterval) | |
{ | |
$this->name = $name; | |
$this->field = $field; | |
$this->calendarInterval = $calendarInterval; | |
} | |
public function payload(): array | |
{ | |
$parameters = [ | |
'field' => $this->field, | |
'calendar_interval' => $this->calendarInterval, | |
]; | |
return [ | |
'date_histogram' => $parameters, | |
]; | |
} | |
public function __construct( | |
string $name, | |
string $field, | |
string $calendarInterval, | |
Aggregation ...$aggregations | |
) { | |
$this->name = $name; | |
$this->field = $field; | |
$this->calendarInterval = $calendarInterval; | |
$this->aggregations = new AggregationCollection(...$aggregations); | |
} | |
public static function create(string $name, string $field, string $calendarInterval, Aggregation ...$aggregations): self | |
{ | |
return new self($name, $field, $calendarInterval, ...$aggregations); | |
} | |
public function payload(): array | |
{ | |
$payload = [ | |
'date_histogram' => [ | |
'field' => $this->field, | |
'calendar_interval' => $this->calendarInterval, | |
], | |
]; | |
if (! $this->aggregations->isEmpty()) { | |
$payload['aggs'] = $this->aggregations->toArray(); | |
} | |
return $payload; | |
} |
…dd tests for all use cases
@wgriffioen thank you for the feedback. I've added sub aggregations and tests as well. It would be great if this PR can now be reviewed and merged. |
Add missing and needed date histogram aggregation
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html