Skip to content

Commit 02c69e4

Browse files
committed
Clarify naming of settings and index configuration
1 parent 95d0bbc commit 02c69e4

File tree

3 files changed

+51
-52
lines changed

3 files changed

+51
-52
lines changed

Classes/Domain/Model/Index.php

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,39 @@ class Index
2929
* @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html
3030
*/
3131
static protected $updatableSettings = [
32-
'settings.index.number_of_replicas',
33-
'settings.index.auto_expand_replicas',
34-
'settings.index.blocks.read_only',
35-
'settings.index.blocks.read',
36-
'settings.index.blocks.write',
37-
'settings.index.blocks.metadata',
38-
'settings.index.refresh_interval',
39-
'settings.index.index_concurrency',
40-
'settings.index.codec',
41-
'settings.index.codec.bloom.load',
42-
'settings.index.fail_on_merge_failure',
43-
'settings.index.translog.flush_threshold_ops',
44-
'settings.index.translog.flush_threshold_size',
45-
'settings.index.translog.flush_threshold_period',
46-
'settings.index.translog.disable_flush',
47-
'settings.index.cache.filter.max_size',
48-
'settings.index.cache.filter.expire',
49-
'settings.index.gateway.snapshot_interval',
50-
'settings.index.routing.allocation.include',
51-
'settings.index.routing.allocation.exclude',
52-
'settings.index.routing.allocation.require',
53-
'settings.index.routing.allocation.disable_allocation',
54-
'settings.index.routing.allocation.disable_new_allocation',
55-
'settings.index.routing.allocation.disable_replica_allocation',
56-
'settings.index.routing.allocation.enable',
57-
'settings.index.routing.allocation.total_shards_per_node',
58-
'settings.index.recovery.initial_shards',
59-
'settings.index.gc_deletes',
60-
'settings.index.ttl.disable_purge',
61-
'settings.index.translog.fs.type',
62-
'settings.index.compound_format',
63-
'settings.index.compound_on_flush',
64-
'settings.index.warmer.enabled',
32+
'index.number_of_replicas',
33+
'index.auto_expand_replicas',
34+
'index.blocks.read_only',
35+
'index.blocks.read',
36+
'index.blocks.write',
37+
'index.blocks.metadata',
38+
'index.refresh_interval',
39+
'index.index_concurrency',
40+
'index.codec',
41+
'index.codec.bloom.load',
42+
'index.fail_on_merge_failure',
43+
'index.translog.flush_threshold_ops',
44+
'index.translog.flush_threshold_size',
45+
'index.translog.flush_threshold_period',
46+
'index.translog.disable_flush',
47+
'index.cache.filter.max_size',
48+
'index.cache.filter.expire',
49+
'index.gateway.snapshot_interval',
50+
'index.routing.allocation.include',
51+
'index.routing.allocation.exclude',
52+
'index.routing.allocation.require',
53+
'index.routing.allocation.disable_allocation',
54+
'index.routing.allocation.disable_new_allocation',
55+
'index.routing.allocation.disable_replica_allocation',
56+
'index.routing.allocation.enable',
57+
'index.routing.allocation.total_shards_per_node',
58+
'index.recovery.initial_shards',
59+
'index.gc_deletes',
60+
'index.ttl.disable_purge',
61+
'index.translog.fs.type',
62+
'index.compound_format',
63+
'index.compound_on_flush',
64+
'index.warmer.enabled',
6565
];
6666

6767
static protected $allowedIndexCreateKeys = [
@@ -94,6 +94,7 @@ class Index
9494
protected $client;
9595

9696
/**
97+
* These are the Flow "Settings" aka Configuration, NOT the index settings
9798
* @var array
9899
*/
99100
protected $settings;
@@ -120,7 +121,7 @@ public function __construct(string $name, Client $client = null)
120121
}
121122

122123
/**
123-
* Inject the settings
124+
* Inject the framework settings
124125
*
125126
* @param array $settings
126127
* @return void
@@ -190,24 +191,24 @@ public function request(string $method, string $path = null, array $arguments =
190191
*/
191192
public function create(): void
192193
{
193-
$indexSettings = $this->getSettings();
194-
$creationSettings = array_filter($indexSettings, static fn($key) => in_array($key, self::$allowedIndexCreateKeys, true), ARRAY_FILTER_USE_KEY);
195-
$this->request('PUT', null, [], json_encode($creationSettings));
194+
$indexConfiguration = $this->getConfiguration();
195+
$indexCreateObject = array_filter($indexConfiguration, static fn($key) => in_array($key, self::$allowedIndexCreateKeys, true), ARRAY_FILTER_USE_KEY);
196+
$this->request('PUT', null, [], json_encode($indexCreateObject));
196197
}
197198

198199
/**
199200
* @return array|null
200201
*/
201-
protected function getSettings(): ?array
202+
protected function getConfiguration(): ?array
202203
{
203204
if ($this->client instanceof Client) {
204205
$path = 'indexes.' . $this->client->getBundle() . '.' . $this->settingsKey;
205206
} else {
206207
$path = 'indexes.default' . '.' . $this->settingsKey;
207208
}
208209

209-
$settings = Arrays::getValueByPath($this->settings, $path);
210-
return $settings !== null ? $this->dynamicIndexSettingService->process($settings, $path, $this->name) : $settings;
210+
$cconfiguration = Arrays::getValueByPath($this->settings, $path);
211+
return $cconfiguration !== null ? $this->dynamicIndexSettingService->process($cconfiguration, $path, $this->name) : $cconfiguration;
211212
}
212213

213214
/**
@@ -216,7 +217,8 @@ protected function getSettings(): ?array
216217
*/
217218
public function updateSettings(): void
218219
{
219-
$settings = $this->getSettings();
220+
// we only ever need the settings path from all the settings.
221+
$settings = $this->getConfiguration()['settings'] ?? [];
220222
$updatableSettings = [];
221223
foreach (static::$updatableSettings as $settingPath) {
222224
$setting = Arrays::getValueByPath($settings, $settingPath);
@@ -289,11 +291,11 @@ public function setSettingsKey(string $settingsKey): void
289291
*/
290292
private function prefixName(): string
291293
{
292-
$indexSettings = $this->getSettings();
293-
if (!isset($indexSettings['prefix']) || empty($indexSettings['prefix'])) {
294+
$indexConfiguration = $this->getConfiguration();
295+
if (!isset($indexConfiguration['prefix']) || empty($indexConfiguration['prefix'])) {
294296
return $this->name;
295297
}
296298

297-
return $indexSettings['prefix'] . '-' . $this->name;
299+
return $indexConfiguration['prefix'] . '-' . $this->name;
298300
}
299301
}

Classes/Service/DynamicIndexSettingService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/**
2222
* Transform indices settings dynamically
23+
* FIXME: This should be called DynamicIndexConfigurationService, the "settings" represent more than what elastic index "settings" are.
2324
*
2425
* @Flow\Scope("singleton")
2526
*/

Tests/Functional/Domain/IndexTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ public function indexWithoutPrefix()
5050
'/index_without_prefix/_settings',
5151
[],
5252
json_encode([
53-
'settings' => [
54-
'index' => [
55-
'number_of_replicas' => 2
56-
]
53+
'index' => [
54+
'number_of_replicas' => 2
5755
]
5856
], JSON_THROW_ON_ERROR)
5957
]
@@ -100,10 +98,8 @@ public function indexWithPrefix()
10098
'/prefix-index_with_prefix/_settings',
10199
[],
102100
json_encode([
103-
'settings' => [
104-
'index' => [
105-
'number_of_replicas' => 1
106-
]
101+
'index' => [
102+
'number_of_replicas' => 1
107103
]
108104
], JSON_THROW_ON_ERROR)
109105
]

0 commit comments

Comments
 (0)