Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "context"
- "encoding/json"
- "fmt"
- "log"
- "os"
- "github.com/olivere/elastic"
- )
- func main() {
- args := os.Args
- if len(args) < 2 {
- log.Fatal("State not informed")
- }
- // check if all elasticsearch env vars were exported
- url := os.Getenv("ELASTIC_URL")
- index := os.Getenv("ELASTIC_INDEX")
- _type := os.Getenv("ELASTIC_TYPE")
- if url == "" || index == "" || _type == "" {
- log.Fatal("Please set all elastic search env vars.")
- }
- // get elastic search client
- client, _ := elastic.NewClient()
- ctx := context.Background()
- // search for state
- state, _ := client.Get().
- Index(index).
- Type(_type).
- Id(args[1]).
- Do(ctx)
- j, _ := json.Marshal(state)
- fmt.Println(string(j))
- }
Add Comment
Please, Sign In to add comment