- Affected version
- 2.1.1
The
Instead of
This way extending
optimize()
function is called with an empty $settings
array during actionOptimize()
and AbstractSource::truncate()
, which results in the index being created with mappings and then index wide config being applied. If custom index configuration which mappings are dependent on is being supplied, this results in an error.
PHP:
public function optimize(array $settings = [], $updateConfig = false)
{
$config = [];
if ($this->es->indexExists())
{
$config = $this->es->getIndexInfo();
$this->es->deleteIndex();
$this->db()->emptyTable('xf_es_index_failed');
}
if ($settings)
{
if (isset($config['settings']))
{
$config['settings'] = array_replace_recursive($config['settings'], $settings);
}
else
{
$config['settings'] = $settings;
}
}
// if we create an index in ES6+, we must force it to be single type
$this->es->forceSingleType($this->es->majorVersion() >= 6);
$config['mappings'] = $this->getExpectedMappingConfig();
$this->es->createIndex($config);
Instead of
getIndexInfo()
, this sort of code should occur before the indexExists()
check;
PHP:
if (!$settings)
{
/** @var \XFES\Service\Configurer $configurer */
$configurer = $this->service('XFES:Configurer', $this->es);
$analyzerConfig = $configurer->getAnalyzerConfig();
/** @var \XFES\Service\Analyzer $analyzer */
$analyzer = $this->service('XFES:Analyzer', $this->es);
$settings = $analyzer->getAnalyzerFromConfig($analyzerConfig);
}
This way extending
getAnalyzerFromConfig()
is all that is required to ensure custom index configuration is persisted across index rebuilds