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

Commit d57cbc0

Browse files
committed
Fixed index delete command
1 parent 9332268 commit d57cbc0

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/Console/ElasticIndexDropCommand.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Illuminate\Console\Command;
66
use ScoutElastic\Facades\ElasticClient;
7-
use ScoutElastic\Payloads\IndexPayload;
7+
use ScoutElastic\IndexConfigurator;
8+
use ScoutElastic\Migratable;
89
use ScoutElastic\Console\Features\RequiresIndexConfiguratorArgument;
10+
use ScoutElastic\Payloads\RawPayload;
911

1012
class ElasticIndexDropCommand extends Command
1113
{
@@ -29,16 +31,38 @@ class ElasticIndexDropCommand extends Command
2931
public function handle()
3032
{
3133
$configurator = $this->getIndexConfigurator();
34+
$indexName = $this->resolveIndexName($configurator);
3235

33-
$payload = (new IndexPayload($configurator))
36+
$payload = (new RawPayload())
37+
->set('index', $indexName)
3438
->get();
3539

3640
ElasticClient::indices()
3741
->delete($payload);
3842

3943
$this->info(sprintf(
4044
'The index %s was deleted!',
41-
$configurator->getName()
45+
$indexName
4246
));
4347
}
48+
49+
/**
50+
* @param IndexConfigurator $configurator
51+
* @return string
52+
*/
53+
protected function resolveIndexName($configurator)
54+
{
55+
if (in_array(Migratable::class, class_uses_recursive($configurator))) {
56+
$payload = (new RawPayload())
57+
->set('name', $configurator->getWriteAlias())
58+
->get();
59+
60+
$aliases = ElasticClient::indices()
61+
->getAlias($payload);
62+
63+
return key($aliases);
64+
} else {
65+
return $configurator->getName();
66+
}
67+
}
4468
}

0 commit comments

Comments
 (0)