How to get Elasticsearch Index Prefix value Magento 2?

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

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.

<?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,

$indexPrefix = $this->getIndexPrefixValue();