Skip to content

Commit 457dfcc

Browse files
authored
Merge pull request #11 from ensi-platform/task-105513-v7
#103513 Отдельные версии для Elasticsearch 7 и 8
2 parents 99137a4 + a46aaba commit 457dfcc

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ class ProductsController
278278
}
279279
```
280280

281+
## Elasticsearch 7 and 8 support.
282+
283+
Due to the incompatibility of clients for Elasticsearch 7 and 8, separate releases will be created for these versions.
284+
Development for each version is carried out in the corresponding branch.
285+
286+
To make changes to version 7, you need to create a task branch based on v7 and make a pull request to it.
287+
For version 8 it is similar, but based on the v8 branch.
288+
281289
## Contributing
282290

283291
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"require": {
1818
"php": "^8.0",
1919
"elasticsearch/elasticsearch": "^7.13",
20-
"ensi/laravel-elastic-query": "^0.3.0",
20+
"ensi/laravel-elastic-query": "^7.0",
2121
"illuminate/contracts": "^8.37 || ^9.0",
2222
"illuminate/support": "^8.0 || ^9.0",
2323
"spatie/laravel-package-tools": "^1.4.3",

composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Data/IndexSeeder.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Ensi\LaravelElasticQuerySpecification\Tests\Data;
44

5-
use Elasticsearch\Client;
5+
use Ensi\LaravelElasticQuery\ElasticClient;
66

77
abstract class IndexSeeder
88
{
@@ -14,14 +14,14 @@ abstract class IndexSeeder
1414

1515
protected bool $recreate;
1616

17-
protected ?Client $client;
17+
protected ?ElasticClient $client;
1818

1919
public function __construct()
2020
{
2121
$this->recreate = config('tests.recreate_index', true);
2222
}
2323

24-
public function setClient(Client $client): void
24+
public function setClient(ElasticClient $client): void
2525
{
2626
$this->client = $client;
2727
}
@@ -50,31 +50,27 @@ public function call(): void
5050

5151
protected function isIndexExists(): bool
5252
{
53-
return $this->client->indices()->exists(['index' => $this->indexName]);
53+
return $this->client->indicesExists($this->indexName);
5454
}
5555

5656
protected function dropIndex(): void
5757
{
58-
$this->client
59-
->indices()
60-
->delete(['index' => $this->indexName]);
58+
$this->client->indicesDelete($this->indexName);
6159
}
6260

6361
protected function createIndex(): void
6462
{
65-
$params = ['index' => $this->indexName];
63+
$settings = [];
6664

6765
if (!empty($this->mappings)) {
68-
data_set($params, 'body.mappings', $this->mappings);
66+
$settings['mappings'] = $this->mappings;
6967
}
7068

7169
if (!empty($this->settings)) {
72-
data_set($params, 'body.settings', $this->settings);
70+
$settings['settings'] = $this->settings;
7371
}
7472

75-
$this->client
76-
->indices()
77-
->create($params);
73+
$this->client->indicesCreate($this->indexName, $settings);
7874
}
7975

8076
protected function loadFixtures(): void
@@ -88,7 +84,7 @@ protected function loadFixtures(): void
8884
);
8985

9086
if ($hasChanges) {
91-
$this->client->indices()->refresh(['index' => $this->indexName]);
87+
$this->client->indicesRefresh($this->indexName);
9288
}
9389
}
9490

@@ -104,7 +100,7 @@ protected function loadFixture(string $path): bool
104100
->flatMap(fn (array $document, int $index) => $this->documentToCommand($document, $index))
105101
->toArray();
106102

107-
$this->client->bulk(['body' => $body]);
103+
$this->client->bulk($this->indexName, $body);
108104

109105
return true;
110106
}

tests/Data/SeedRunner.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Ensi\LaravelElasticQuerySpecification\Tests\Data;
44

5-
use Elasticsearch\Client;
6-
use Elasticsearch\ClientBuilder;
5+
use Ensi\LaravelElasticQuery\ElasticClient;
76

87
class SeedRunner
98
{
109
private static ?self $instance;
1110

1211
private array $processed = [];
1312

14-
protected function __construct(private Client $client)
13+
protected function __construct(private ElasticClient $client)
1514
{
1615
}
1716

@@ -38,9 +37,7 @@ public static function getInstance(): self
3837

3938
private static function createInstance(): self
4039
{
41-
$client = ClientBuilder::create()
42-
->setHosts(config('laravel-elastic-query.connection.hosts'))
43-
->build();
40+
$client = ElasticClient::fromConfig(config('laravel-elastic-query.connection'));
4441

4542
return new self($client);
4643
}

0 commit comments

Comments
 (0)