Skip to content

Commit

Permalink
Elasticsearch 8.x Support (#18)
Browse files Browse the repository at this point in the history
* bulk changes for phpunit9 deprecation warnings of the test cases

* composer update and readme changes for elasticsearch 8.0

* MovingAverage pipeline aggregation removed for ES8.x

* Remove deprecated _time and _term sort orders

* Remove deprecated date histogram interval and changed as calendar_interval and fixed interval

* php 7.1 support droped and the version increased to ^7.4

* php 7.1, 7.2 and 7.3 remove d from the github ci

* phpcs fix for the changes

* phpunit upgraged to 9.x

* ::class used instead of text

* Removes typed endpoint from search on tests

* cutoff_frequency sample removed for CommonTerms query

* Remove CommonTermsQuery and cutoff_frequency params

* functional test for date histogram

* elasticsearch version increased for the test node

* removed e_user_deprecated exceptions for GeoShape query

* php8.1 added on test matrix

* upgrade the version of elasticsearch to 8.0.0

* fix for the elasticsearch-php version

* Update composer.json

* Add a psr 18 client implementation (nyholm/psr7)

Co-authored-by: Alexander Schranz <alexander@sulu.io>
  • Loading branch information
hkulekci and alexander-schranz committed Mar 25, 2022
1 parent 80c890f commit 86e37b5
Show file tree
Hide file tree
Showing 45 changed files with 314 additions and 354 deletions.
18 changes: 5 additions & 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 @@ -36,9 +24,13 @@ jobs:
lint: true
symfony-version: '^5.0'

- php-version: '8.1'
lint: true
symfony-version: '^5.0'

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
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
{
"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",
"nyholm/psr7": "^1.5",
"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
Loading

0 comments on commit 86e37b5

Please sign in to comment.