Last active
August 29, 2015 14:18
-
-
Save olivere/c76a110248b36d4aa135 to your computer and use it in GitHub Desktop.
Connecting to Elasticsearch via Elastic (the infinite loop edition)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"runtime" | |
"github.com/olivere/elastic" | |
) | |
func main() { | |
var n int | |
for { | |
n++ | |
// Create a client | |
u := elastic.SetURL("http://127.0.0.1:9200") | |
cl, err := elastic.NewClient(u) | |
if err != nil { | |
fmt.Printf("%v\n", err) | |
continue | |
} else { | |
fmt.Printf("%d\r", n) | |
} | |
time.Sleep(100 * time.Millisecond) | |
// Do something | |
_, err = cl.ElasticsearchVersion("http://127.0.0.1:9200") | |
if err != nil { | |
fmt.Printf("%v\n", err) | |
} | |
// Stop and GC the client | |
// (otherwise the server will continue running and sniffing) | |
cl.Stop() | |
cl = nil | |
runtime.GC() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment