Step 1
Remove the line:
Step 2
composer require magento/module-elasticsearch-8 --update-with-all-dependencies
Step 3
bin/magento module:enable Magento_Elasticsearch8
Step 4
bin/magento setup:upgrade
bin/magento cache:enable
rm -rf var/di var/generation generated/*
bin/magento setup:di:compile
rm -rf pub/static/*
bin/magento setup:static-content:deploy -f en_US <additional locales>
Step 5
bin/magento config:set catalog/search/engine elasticsearch8
bin/magento config:set catalog/search/elasticsearch8_index_prefix <your value>
bin/magento cache:clean
Step 6
bin/magento indexer:reindex
bin/magento cron:run --bootstrap=standaloneProcessStarted=1
bin/magento cache:clean