Fatal error: Uncaught Error: Class 'Elasticsearch\ClientBuilder' not found

Problem

When you run search reindex or perform search by store catalog, Magento 2 returns error message:

Fatal error: Uncaught Error: Class 'Elasticsearch\ClientBuilder' not found

Reason

The elasticsearch php library wasn’t installed in Magento 2.

This issue is possible only if Elastic Search Ultimate was installed without using composer (manual installation). And not all steps from user manual were completed.

Solution

To solve this error, you need run next command in store root directory:

composer require elasticsearch/elasticsearch:~5.1

This command will install elasticsearch php library (for ES 5.1/6.2) and additional required libraries.