transfer.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "github.com/olivere/elastic/v7"
  7. )
  8. func main() {
  9. // 创建一个新的 Elasticsearch 客户端
  10. client, err := elastic.NewClient(
  11. elastic.SetURL("http://elasticsearch-o-00g0ootdnc99.escloud.volces.com:9200"),
  12. elastic.SetBasicAuth("admin", "F37ZMTyjwTNuQC"), // 设置用户名和密码
  13. //elastic.SetURL("https://410bb6fe.r11.cpolar.top"),
  14. //elastic.SetBasicAuth("elastic", "123456"), // 设置用户名和密码
  15. )
  16. if err != nil {
  17. log.Fatalf("Error creating the client: %s", err)
  18. }
  19. // 检查 Elasticsearch 版本
  20. info, code, err := client.Ping("http://elasticsearch-o-00g0ootdnc99.escloud.volces.com:9200").Do(context.Background())
  21. if err != nil {
  22. log.Fatalf("Error connecting to Elasticsearch: %s", err)
  23. }
  24. fmt.Printf("Elasticsearch returned with code %d and version %s\n", code, info.Version.Number)
  25. // 获取所有索引
  26. indices, err := client.CatIndices().Do(context.Background())
  27. if err != nil {
  28. log.Fatalf("Error getting the indices: %s", err)
  29. }
  30. // 打印所有索引
  31. for _, index := range indices {
  32. fmt.Printf("Index: %s\n", index.Index)
  33. }
  34. }