It appears that the username/pwd was either not provided when accessing the URL, or the authentication details were invalid.
curl -u username:password -X GET "http://localhost:9200"
Configure Elasticsearch in the app/etc/env.php
<?php
return [
'system' => [
'default' => [
'catalog' => [
'search' => [
'engine' => 'elasticsearch7', // Change this based on your Elasticsearch version (elasticsearch6, elasticsearch7)
'elasticsearch7_server_hostname' => 'localhost', // Elasticsearch server hostname
'elasticsearch7_server_port' => '9200', // Elasticsearch server port
'elasticsearch7_index_prefix' => 'magento2', // Optional: Prefix for Elasticsearch indexes
'elasticsearch7_enable_auth' => '1', // Set to 1 if authentication is required
'elasticsearch7_server_timeout' => '15', // Connection timeout in seconds
'elasticsearch7_username' => 'your-username', // Elasticsearch username if authentication is required
'elasticsearch7_password' => 'your-password' // Elasticsearch password if authentication is required
]
]
]
]
];
If not in config file then check in in your DB config table for authentication details.
To check if Elasticsearch is enabled on your server. You can verify this by running the following command:
sudo systemctl status elasticsearch
If Elasticsearch is not enabled, you can enable it with this command:
sudo systemctl is-enabled elasticsearch
If you don’t get any output, it indicates that Elasticsearch is not installed, and you'll need to set it up. Follow these steps to install Elasticsearch:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.rpm.sha512
shasum -a 512 -c elasticsearch-6.1.1.rpm.sha512
sudo rpm --install elasticsearch-6.1.1.rpm
sudo chkconfig --add elasticsearch
sudo -i service elasticsearch start
After the setup is complete, validate the installation by running:
sudo systemctl status elasticsearch
If Elasticsearch is enabled, proceed with running the necessary Magento commands and check if the issue is resolved.