Elasticsearch Index Prefix parameter used to the indexing of search term prefixes to speed up prefix searches on a website.
You can set Elasticsearch Index Prefix from the admin panel
1 | Settings -> Configuration -> Catalog -> Catalog -> Catalog Search -> Elasticsearch Index Prefix. |
Out of the box, the default value is the magento2.
If you are using a single elastic search instance for more than one Magento installation, you need to specify a unique prefix for each installation to prevent mess up indexing terms with the different installation. Like, production, staging, development.
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 | <?php namespace Jesadiya\IndexPrefix\Model; use Magento\Elasticsearch\Model\Config; class IndexPrefix { /** * @var Config */ private $config; public function __construct( Config $config ) { $this->config = $config; } /** * @return string */ public function getIndexPrefixValue(): string { return $this->config->getIndexPrefix(); } } |
Get the value of index prefix by the given syntax,
1 | $indexPrefix = $this->getIndexPrefixValue(); |