How to check elasticsearch is enabled programmatically Magento 2?

Magento 2.4 Out of the box supports Primary Search Engines is Elasticsearch.

If your site having some third party search engine installed or want to know about programmatically for the elastic search is enable or not in your code, you can know it using the given code snippet.

Just instantiate the Magento\Elasticsearch\Model\Config class to your __construct() method.

Check with the given syntax,

The result will be true if your site has enabled elastic search as default search engine.

Output:
Boolean