Skip to content
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

Elasticsearch 8.0 support #2

Merged
merged 15 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '7.1'
lint: false
symfony-version: '^2.8'

- php-version: '7.2'
lint: false
symfony-version: '^3.4'

- php-version: '7.3'
lint: false
symfony-version: '^4.4'

- php-version: '7.4'
lint: true
symfony-version: '^5.0'
Expand All @@ -38,7 +26,7 @@ jobs:

services:
elasticsearch:
image: elasticsearch:7.5.2
image: elasticsearch:8.0.0
ports:
- 9200:9200
env:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ With some basic changes to support wider range of Symfony Versions.

| Version | Supported Elasticsearch Version | Supported Symfony Version |
|---------|---------------------------------|---------------------------|
| 8.x | ^8.0 | ^5.0, |
| 7.x | ^7.0 | ^5.0, ^4.0, ^3.4, ^2.8 |
| 6.x | ^6.0 | ^5.0, ^4.0, ^3.4, ^2.8 |
| 5.x | ^5.0 | ^5.0, ^4.0, ^3.4, ^2.8 |
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
{
"name": "Handcrafted in the Alps Team",
"homepage": "https://github.com/handcraftedinthealps/ElasticsearchDSL/graphs/contributors"
},
{
"name": "Haydar KULEKCI",
"homepage": "https://github.com/hkulekci/ElasticsearchDSL/graphs/contributors"
}
],
"require": {
"php": "^7.1|^8.0",
"php": "^7.4 || ^8.0",
"symfony/serializer": "^2.8 || ^3.4 || ^4.0 || ^5.0",
"elasticsearch/elasticsearch": "^7.0"
"elasticsearch/elasticsearch": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.26 || ^7.5.20 || ^8.0",
"phpunit/phpunit": "^5.7.26 || ^7.5.20 || ^8.0 || ^9.0",
"squizlabs/php_codesniffer": "^2.0 || ^3.0"
},
"suggest": {
Expand Down
6 changes: 3 additions & 3 deletions docs/Aggregation/Bucketing/DateHistogram.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Example of expressions for interval: `year`, `quarter`, `month`, `week`, `day`,
"articles_over_time" : {
"date_histogram" : {
"field" : "date",
"interval" : "month"
"calendar_interval" : "month"
}
}
}
Expand Down Expand Up @@ -42,7 +42,7 @@ to provide a custom format to the results of the query:
"articles_over_time" : {
"date_histogram" : {
"field" : "date",
"interval" : "1M",
"calendar_interval" : "1M",
"format" : "yyyy-MM-dd"
}
}
Expand All @@ -63,4 +63,4 @@ $search->addAggregation($dateHistogramAggregation);
$queryArray = $search->toArray();

```
[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
46 changes: 0 additions & 46 deletions docs/Query/FullText/CommonTerms.md

This file was deleted.

75 changes: 66 additions & 9 deletions src/Aggregation/Bucketing/DateHistogramAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ class DateHistogramAggregation extends AbstractAggregation
*/
protected $interval;

/**
* @var string
*/
protected $calendarInterval;

/**
* @var string
*/
protected $fixedInterval;

/**
* @var string
*/
Expand All @@ -37,34 +47,76 @@ class DateHistogramAggregation extends AbstractAggregation
* Inner aggregations container init.
*
* @param string $name
* @param string $field
* @param string $interval
* @param string|null $field
* @param string|null $interval
* @param string|null $format
*/
public function __construct($name, $field = null, $interval = null, $format = null)
public function __construct($name, string $field = null, string $interval = null, string $format = null)
{
parent::__construct($name);

$this->setField($field);
$this->setInterval($interval);
$this->setCalendarInterval($interval);
$this->setFormat($format);
}

/**
* @return int
* @return string
* @deprecated use getCalendarInterval instead
*/
public function getInterval()
{
return $this->interval;
return $this->calendarInterval;
}

/**
* @param string $interval
* @deprecated use setCalendarInterval instead
*
* @return $this
*/
public function setInterval($interval)
{
$this->interval = $interval;
$this->setCalendarInterval($interval);

return $this;
}


/**
* @return string
*/
public function getFixedInterval()
{
return $this->fixedInterval;
}

/**
* @param string $interval
* @return $this
*/
public function setFixedInterval($interval)
{
$this->fixedInterval = $interval;

return $this;
}

/**
* @return string
*/
public function getCalendarInterval()
{
return $this->calendarInterval;
}

/**
* @param string $interval
* @return $this
*/
public function setCalendarInterval($interval)
{
$this->calendarInterval = $interval;

return $this;
}
Expand Down Expand Up @@ -94,15 +146,20 @@ public function getType()
*/
public function getArray()
{
if (!$this->getField() || !$this->getInterval()) {
if (!$this->getField() || !($this->getCalendarInterval() || $this->getFixedInterval())) {
throw new \LogicException('Date histogram aggregation must have field and interval set.');
}

$out = [
'field' => $this->getField(),
'interval' => $this->getInterval(),
];

if ($this->getCalendarInterval()) {
$out['calendar_interval'] = $this->getCalendarInterval();
} elseif ($this->getFixedInterval()) {
$out['fixed_interval'] = $this->getFixedInterval();
}

if (!empty($this->format)) {
$out['format'] = $this->format;
}
Expand Down
17 changes: 11 additions & 6 deletions src/Aggregation/Metric/PercentilesAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ class PercentilesAggregation extends AbstractAggregation
* Inner aggregations container init.
*
* @param string $name
* @param string $field
* @param array $percents
* @param string $script
* @param int $compression
* @param string|null $field
* @param array|null $percents
* @param string|null $script
* @param int|null $compression
*/
public function __construct($name, $field = null, $percents = null, $script = null, $compression = null)
{
public function __construct(
string $name,
string $field = null,
array $percents = null,
string $script = null,
int $compression = null
) {
parent::__construct($name);

$this->setField($field);
Expand Down
28 changes: 0 additions & 28 deletions src/Aggregation/Pipeline/MovingAverageAggregation.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/BuilderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public function get($name)
*
* @return BuilderInterface[]
*/
public function all($type = null)
public function all(string $type = null)
{
return array_filter(
$this->bag,
/** @var BuilderInterface $builder */
function (BuilderInterface $builder) use ($type) {
return $type === null || $builder->getType() == $type;
static function (BuilderInterface $builder) use ($type) {
return $type === null || $builder->getType() === $type;
}
);
}
Expand Down
71 changes: 0 additions & 71 deletions src/Query/FullText/CommonTermsQuery.php

This file was deleted.

Loading