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