1 | <?php |
||
2 | |||
3 | namespace App\Console\Commands; |
||
4 | |||
5 | use Elasticsearch; |
||
6 | use Illuminate\Console\Command; |
||
7 | |||
8 | class NntmuxCreateESIndexes extends Command |
||
9 | { |
||
10 | /** |
||
11 | * The name and signature of the console command. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $signature = 'nntmux:create-es-indexes'; |
||
16 | |||
17 | /** |
||
18 | * The console command description. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $description = 'Create ElasticSearch Indexes'; |
||
23 | |||
24 | /** |
||
25 | * Execute the console command. |
||
26 | */ |
||
27 | public function handle(): void |
||
28 | { |
||
29 | if (Elasticsearch::indices()->exists(['index' => 'releases'])) { |
||
30 | Elasticsearch::indices()->delete(['index' => 'releases']); |
||
31 | } |
||
32 | $releases_index = [ |
||
33 | 'index' => 'releases', |
||
34 | 'body' => [ |
||
35 | 'settings' => [ |
||
36 | 'number_of_shards' => 2, |
||
37 | 'number_of_replicas' => 0, |
||
38 | ], |
||
39 | 'mappings' => [ |
||
40 | 'properties' => [ |
||
41 | 'id' => [ |
||
42 | 'type' => 'long', |
||
43 | 'index' => false, |
||
44 | ], |
||
45 | 'name' => ['type' => 'text'], |
||
46 | 'searchname' => [ |
||
47 | 'type' => 'text', |
||
48 | 'fields' => [ |
||
49 | 'sort' => [ |
||
50 | 'type' => 'keyword', |
||
51 | ], |
||
52 | ], |
||
53 | ], |
||
54 | 'plainsearchname' => [ |
||
55 | 'type' => 'text', |
||
56 | 'fields' => [ |
||
57 | 'sort' => [ |
||
58 | 'type' => 'keyword', |
||
59 | ], |
||
60 | ], |
||
61 | ], |
||
62 | 'categories_id' => [ |
||
63 | 'type' => 'text', |
||
64 | ], |
||
65 | 'fromname' => [ |
||
66 | 'type' => 'text', |
||
67 | ], |
||
68 | 'filename' => [ |
||
69 | 'type' => 'text', |
||
70 | ], |
||
71 | 'add_date' => [ |
||
72 | 'type' => 'date', |
||
73 | 'format' => 'yyyy-MM-dd HH:mm:ss', |
||
74 | ], |
||
75 | 'post_date' => [ |
||
76 | 'type' => 'date', |
||
77 | 'format' => 'yyyy-MM-dd HH:mm:ss', |
||
78 | ], |
||
79 | ], |
||
80 | ], |
||
81 | ], |
||
82 | ]; |
||
83 | |||
84 | $response = Elasticsearch::indices()->create($releases_index); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
85 | |||
86 | $this->info('Index releases created successfully'); |
||
87 | if (Elasticsearch::indices()->exists(['index' => 'predb'])) { |
||
88 | Elasticsearch::indices()->delete(['index' => 'predb']); |
||
89 | } |
||
90 | $predb_index = [ |
||
91 | 'index' => 'predb', |
||
92 | 'body' => [ |
||
93 | 'settings' => [ |
||
94 | 'number_of_shards' => 2, |
||
95 | 'number_of_replicas' => 0, |
||
96 | ], |
||
97 | 'mappings' => [ |
||
98 | 'properties' => [ |
||
99 | 'id' => [ |
||
100 | 'type' => 'long', |
||
101 | 'index' => false, |
||
102 | ], |
||
103 | 'title' => [ |
||
104 | 'type' => 'text', |
||
105 | 'fields' => [ |
||
106 | 'sort' => [ |
||
107 | 'type' => 'keyword', |
||
108 | ], |
||
109 | ], |
||
110 | ], |
||
111 | 'filename' => ['type' => 'text'], |
||
112 | 'source' => ['type' => 'text'], |
||
113 | ], |
||
114 | ], |
||
115 | ], |
||
116 | |||
117 | ]; |
||
118 | |||
119 | $response = Elasticsearch::indices()->create($predb_index); |
||
120 | |||
121 | $this->info('Index predb created successfully'); |
||
122 | |||
123 | $this->info('All done! ElasticSearch indexes are created now.'); |
||
124 | } |
||
125 | } |
||
126 |