Use the official elastic/go-elasticsearch client to connect to Elasticsearch from Go.
package main
import (
"context"
"log"
"github.com/elastic/go-elasticsearch/v8"
)
func main() {
es, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
})
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
res, err := es.Info(ctx)
if err != nil {
log.Fatal(err)
}
log.Println(res.String())
}