'Could not validate a connection to Elasticsearch. Unknown 401 error from Elasticsearch null

{
  "name" : "DESKTOP-BNTBBBG",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "DlRfjfPlRg69wUBRfy3kKQ",
  "version" : {
    "number" : "8.1.3",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "39afaa3c0fe7db4869a161985e240bd7182d7a07",
    "build_date" : "2022-04-19T08:13:25.444693396Z",
    "build_snapshot" : false,
    "lucene_version" : "9.0.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

But When running this command

php bin/magento setup:install --base-url="http://versionup.magento.com" --db-host="localhost" --db-name="magento2" --db-user="magento2" --db-password="magento2" --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="Admin@123456" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200 

Could not validate a connection to Elasticsearch. Unknown 401 error from Elasticsearch null



Solution 1:[1]

i have the same problem, but now it's fixed.

make sure you enable xpack.security.http.ssl on elasticsearch.yml. because I disable it before.

then change the host to:

--elasticsearch-host="https://localhost"

then add more options to your command for authentication:

--elasticsearch-enable-auth=true --elasticsearch-username="elastic" --elasticsearch-password="your password"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1