As of version 2.3.6, Magento Commerce supports Elasticsearch 7.x, with a preference for 7.6.x. Support for Elasticsearch 6.x has been deprecated, but it can still be used. Both Elasticsearch 2.x and 5.x have reached end-of-life and are no longer supported.
Change the Elasticsearch Client version
If you need to work with Elasticsearch 7.1.x, run the following command:
1 composer require "elasticsearch/elasticsearch:~7.1"
To work with Elasticsearch 6.8.x, run the following command:
1 composer require "elasticsearch/elasticsearch:~6.8"
Then configure Elasticsearch within Magento Admin.