Create 2 files: main.go and docker-compose.yml. Once both are created use docker-compose up and it will build the necessary files and start Elastic Search.
I found it necessary to add elastic.SetSniff(false) or I could not connect. Also remember the docker containers have security enabled for Elasticsearch with the password set as elastic:changeme. You can test it using curl:
curl http://127.0.0.1:9200/_cat/health -u elastic:changemeOnce it is running you can successfully run the main.go file using go run main.go.