title: Elasticsearch with PHP connection not working
body: <p>I am using <code>Elasticsearch 8.1</code>. It is running on port <code>9200</code>. When I execute from POSTMAN,</p>
  <pre><code>https://localhost:9200/learn/_search
  </code></pre>
  <p>with Authorization: <code>Type: Basic Auth</code> and username &amp; password, I can see the result.</p>
  <p>But now I want to implement this using PHP. I have installed <code>&quot;elasticsearch/elasticsearch&quot;: &quot;^8.0&quot;</code> in my composer. This is the code I have tried.</p>
  <pre><code>use Elastic\Elasticsearch\ClientBuilder;
  
  $hosts = [
      'host' =&gt; 'localhost',
      'port' =&gt; '9200',
      'scheme' =&gt; 'https',
      'user' =&gt; 'elastic',
      'pass' =&gt; 'LisRrIul9oMKh2deJkMv'
  ];
  
  $client = ClientBuilder::create()
      -&gt;setHosts($hosts)
      -&gt;build();
  
  
  $params = [
      'index' =&gt; 'learn',
  ];
  
  $results = $client-&gt;search($params);
  
  echo &quot;&lt;pre&gt;&quot;;
  print_r($results);
  </code></pre>
  <p>I am getting</p>
  <pre><code>`[Thu Mar 31 22:07:09 2022] 127.0.0.1:44396 [500]: GET / - Uncaught Elastic\Elasticsearch\Exception\ClientResponseException: 404 Not Found: &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;404 Not Found&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Not Found&lt;/h1&gt;
  &lt;p&gt;The requested URL was not found on this server.&lt;/p&gt;
  &lt;hr&gt;
  &lt;address&gt;Apache/2.4.41 (Ubuntu) Server at localhost Port 80&lt;/address&gt;
  &lt;/body&gt;&lt;/html&gt;
   in /home/user/Projects/Els/my-apps/esphpsearch/vendor/elasticsearch/elasticsearch/src/Response/Elasticsearch.php:65
  Stack trace:
  #0 /home/user/Projects/Els/my-apps/esphpsearch/vendor/elasticsearch/elasticsearch/src/Client.php(168): Elastic\Elasticsearch\Response\Elasticsearch-&gt;setResponse()
  #1 /home/user/Projects/Els/my-apps/esphpsearch/vendor/elasticsearch/elasticsearch/src/Traits/ClientEndpointsTrait.php(1521): Elastic\Elasticsearch\Client-&gt;sendRequest()
  #2 /home/user/Projects/Els/my-apps/esphpsearch/index.php(24): Elastic\Elasticsearch\Client-&gt;search()
  #3 {main}
  `
  </code></pre>