Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace IQDEV\ElasticSearch\Indexer;
use Elastic\Elasticsearch\Client;
use IQDEV\ElasticSearch\Configuration;
final class IndexRunner
{
private Client $esClient;
private Configuration $configuration;
public function __construct(
Client $esClient,
Configuration $configuration
) {
$this->esClient = $esClient;
$this->configuration = $configuration;
}
public function run(IndexProvider $indexProvider)
{
if ($this->esClient->indices()->exists(['index' => $this->configuration->getIndexName()])->asBool() === false) {
$this->esClient->indices()->create(
[
'index' => $this->configuration->getIndexName(),
'body' => [
'mappings' => $this->configuration->getMapping(),
],
]
);
}
foreach ($indexProvider->get() as $index) {
if (!$index instanceof Index) {
continue;
}
$esIndex = $index->es();
$this->esClient->index($esIndex);
}
}
}