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

Commit 97474c6

Browse files
author
ivan.babenko
committed
"ES7 support"
1 parent c3e106a commit 97474c6

File tree

6 files changed

+14
-32
lines changed

6 files changed

+14
-32
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"require": {
2424
"php": "^7.1.3",
25-
"elasticsearch/elasticsearch": "^6.0",
25+
"elasticsearch/elasticsearch": "^7.0",
2626
"laravel/scout": "^7.0"
2727
},
2828
"require-dev": {

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ services:
2727
MYSQL_ROOT_PASSWORD: root
2828
MYSQL_DATABASE: app
2929
elastic:
30-
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
30+
image: elasticsearch:7.1.1
31+
environment:
32+
discovery.type: single-node

src/Console/ElasticIndexCreateCommand.php

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

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

3938
ElasticClient::indices()
@@ -54,7 +53,7 @@ protected function createWriteAlias()
5453
{
5554
$configurator = $this->getIndexConfigurator();
5655

57-
if (! in_array(Migratable::class, class_uses_recursive($configurator))) {
56+
if (!in_array(Migratable::class, class_uses_recursive($configurator))) {
5857
return;
5958
}
6059

src/Console/ElasticIndexUpdateCommand.php

Lines changed: 2 additions & 11 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,15 +57,6 @@ 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-
6960
$indices->open($indexPayload);
7061
} catch (Exception $exception) {
7162
$indices->open($indexPayload);
@@ -88,7 +79,7 @@ protected function createWriteAlias()
8879
{
8980
$configurator = $this->getIndexConfigurator();
9081

91-
if (! in_array(Migratable::class, class_uses_recursive($configurator))) {
82+
if (!in_array(Migratable::class, class_uses_recursive($configurator))) {
9283
return;
9384
}
9485

src/Console/ElasticMigrateCommand.php

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

7978
ElasticClient::indices()
@@ -116,16 +115,6 @@ protected function updateTargetIndex()
116115
$indices->putSettings($targetIndexSettingsPayload);
117116
}
118117

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-
129118
$indices->open($targetIndexPayload);
130119
} catch (Exception $exception) {
131120
$indices->open($targetIndexPayload);
@@ -169,7 +158,8 @@ protected function updateTargetIndexMapping()
169158
$payload = (new RawPayload())
170159
->set('index', $targetIndex)
171160
->set('type', $targetType)
172-
->set('body.'.$targetType, $mapping)
161+
->set('include_type_name', 'true')
162+
->set('body.' . $targetType, $mapping)
173163
->get();
174164

175165
ElasticClient::indices()
@@ -339,7 +329,7 @@ public function handle()
339329
$sourceModel = $this->getModel();
340330
$sourceIndexConfigurator = $sourceModel->getIndexConfigurator();
341331

342-
if (! in_array(Migratable::class, class_uses_recursive($sourceIndexConfigurator))) {
332+
if (!in_array(Migratable::class, class_uses_recursive($sourceIndexConfigurator))) {
343333
$this->error(sprintf(
344334
'The %s index configurator must use the %s trait.',
345335
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);
48+
$payload = (new TypePayload($model))
49+
->set('body.' . $model->searchableAs(), $mapping)
50+
->set('include_type_name', 'true');
4951

5052
if (in_array(Migratable::class, class_uses_recursive($configurator))) {
5153
$payload->useAlias('write');
5254
}
5355

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

0 commit comments

Comments
 (0)