-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
36 lines (29 loc) · 785 Bytes
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"encoding/json"
"log"
"strings"
"github.com/elastic/go-elasticsearch/v8"
)
func GetInfo(es *elasticsearch.Client) {
var r map[string]interface{}
res, err := es.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
res.IsError()
if err != nil {
log.Fatalf("Error: %s", res.String())
}
// Deserialize the response into a map.
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
}
// Print client and server version numbers.
log.Println()
log.Println(strings.Repeat("-", 37))
log.Printf("Client: %s", elasticsearch.Version)
log.Printf("Server: %s", r["version"].(map[string]interface{})["number"])
log.Println(strings.Repeat("-", 37))
log.Println()
}