Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit e8f6c13

Browse files
author
ivan.babenko
committed
Revert "ES7 support"
This reverts commit 3ab3a7a
1 parent d57cbc0 commit e8f6c13

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.1.3",
25-
"elasticsearch/elasticsearch": "^7.0",
26-
"laravel/scout": "^7.0"
24+
"php": ">=7.1.3",
25+
"elasticsearch/elasticsearch": "6.*",
26+
"laravel/scout": "7.*"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^7.0",
30-
"mockery/mockery": "^1.0"
29+
"phpunit/phpunit": "7.*",
30+
"mockery/mockery": "1.*"
3131
},
3232
"autoload": {
3333
"psr-4": {

docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.7'
22

33
services:
44
php:
5-
image: babenkoivan/scout-elasticsearch-driver-php-cli:php7.2-laravel5.8
5+
image: babenkoivan/scout-elasticsearch-driver-php-cli:1.0.1
66
command: >
77
sh -c 'check-connection mysql 3306 &&
88
check-connection elastic 9200 &&
@@ -27,6 +27,4 @@ services:
2727
MYSQL_ROOT_PASSWORD: root
2828
MYSQL_DATABASE: app
2929
elastic:
30-
image: elasticsearch:7.1.1
31-
environment:
32-
discovery.type: single-node
30+
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4

src/Console/ElasticIndexCreateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protected function createIndex()
3333

3434
$payload = (new IndexPayload($configurator))
3535
->setIfNotEmpty('body.settings', $configurator->getSettings())
36+
->setIfNotEmpty('body.mappings._default_', $configurator->getDefaultMapping())
3637
->get();
3738

3839
ElasticClient::indices()
@@ -53,7 +54,7 @@ protected function createWriteAlias()
5354
{
5455
$configurator = $this->getIndexConfigurator();
5556

56-
if (!in_array(Migratable::class, class_uses_recursive($configurator))) {
57+
if (! in_array(Migratable::class, class_uses_recursive($configurator))) {
5758
return;
5859
}
5960

src/Console/ElasticIndexUpdateCommand.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function updateIndex()
3939

4040
$indices = ElasticClient::indices();
4141

42-
if (!$indices->exists($indexPayload)) {
42+
if (! $indices->exists($indexPayload)) {
4343
throw new LogicException(sprintf(
4444
'Index %s doesn\'t exist',
4545
$configurator->getName()
@@ -57,6 +57,15 @@ protected function updateIndex()
5757
$indices->putSettings($indexSettingsPayload);
5858
}
5959

60+
if ($defaultMapping = $configurator->getDefaultMapping()) {
61+
$indexMappingPayload = (new IndexPayload($configurator))
62+
->set('type', '_default_')
63+
->set('body._default_', $defaultMapping)
64+
->get();
65+
66+
$indices->putMapping($indexMappingPayload);
67+
}
68+
6069
$indices->open($indexPayload);
6170
} catch (Exception $exception) {
6271
$indices->open($indexPayload);
@@ -79,7 +88,7 @@ protected function createWriteAlias()
7988
{
8089
$configurator = $this->getIndexConfigurator();
8190

82-
if (!in_array(Migratable::class, class_uses_recursive($configurator))) {
91+
if (! in_array(Migratable::class, class_uses_recursive($configurator))) {
8392
return;
8493
}
8594

src/Console/ElasticMigrateCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected function createTargetIndex()
7373
$payload = (new RawPayload())
7474
->set('index', $targetIndex)
7575
->setIfNotEmpty('body.settings', $sourceIndexConfigurator->getSettings())
76+
->setIfNotEmpty('body.mappings._default_', $sourceIndexConfigurator->getDefaultMapping())
7677
->get();
7778

7879
ElasticClient::indices()
@@ -115,6 +116,16 @@ protected function updateTargetIndex()
115116
$indices->putSettings($targetIndexSettingsPayload);
116117
}
117118

119+
if ($defaultMapping = $sourceIndexConfigurator->getDefaultMapping()) {
120+
$targetIndexMappingPayload = (new RawPayload())
121+
->set('index', $targetIndex)
122+
->set('type', '_default_')
123+
->set('body._default_', $defaultMapping)
124+
->get();
125+
126+
$indices->putMapping($targetIndexMappingPayload);
127+
}
128+
118129
$indices->open($targetIndexPayload);
119130
} catch (Exception $exception) {
120131
$indices->open($targetIndexPayload);
@@ -158,8 +169,7 @@ protected function updateTargetIndexMapping()
158169
$payload = (new RawPayload())
159170
->set('index', $targetIndex)
160171
->set('type', $targetType)
161-
->set('include_type_name', 'true')
162-
->set('body.' . $targetType, $mapping)
172+
->set('body.'.$targetType, $mapping)
163173
->get();
164174

165175
ElasticClient::indices()
@@ -329,7 +339,7 @@ public function handle()
329339
$sourceModel = $this->getModel();
330340
$sourceIndexConfigurator = $sourceModel->getIndexConfigurator();
331341

332-
if (!in_array(Migratable::class, class_uses_recursive($sourceIndexConfigurator))) {
342+
if (! in_array(Migratable::class, class_uses_recursive($sourceIndexConfigurator))) {
333343
$this->error(sprintf(
334344
'The %s index configurator must use the %s trait.',
335345
get_class($sourceIndexConfigurator),

src/Console/ElasticUpdateMappingCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ElasticUpdateMappingCommand extends Command
3030
*/
3131
public function handle()
3232
{
33-
if (!$model = $this->getModel()) {
33+
if (! $model = $this->getModel()) {
3434
return;
3535
}
3636

@@ -45,14 +45,14 @@ public function handle()
4545
throw new LogicException('Nothing to update: the mapping is not specified.');
4646
}
4747

48-
$payload = (new TypePayload($model))
49-
->set('body.' . $model->searchableAs(), $mapping)
50-
->set('include_type_name', 'true');
48+
$payload = new TypePayload($model);
5149

5250
if (in_array(Migratable::class, class_uses_recursive($configurator))) {
5351
$payload->useAlias('write');
5452
}
5553

54+
$payload->set('body.'.$model->searchableAs(), $mapping);
55+
5656
ElasticClient::indices()
5757
->putMapping($payload->get());
5858

0 commit comments

Comments
 (0)