| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
// Connect simply connects to Elasticsearch. |
| 6 |
// |
| 7 |
// Example |
| 8 |
// |
| 9 |
// |
| 10 |
// connect -url=http://127.0.0.1:9200 -sniff=false |
| 11 |
// |
| 12 |
package main |
| 13 |
|
| 14 |
import ( |
| 15 |
"flag" |
| 16 |
"fmt" |
| 17 |
"log" |
| 18 |
|
| 19 |
"gopkg.in/olivere/elastic.v5" |
| 20 |
) |
| 21 |
|
| 22 |
func main() { |
| 23 |
var ( |
| 24 |
url = flag.String("url", "http://localhost:9200", "Elasticsearch URL") |
| 25 |
sniff = flag.Bool("sniff", true, "Enable or disable sniffing") |
| 26 |
) |
| 27 |
flag.Parse() |
| 28 |
log.SetFlags(0) |
| 29 |
|
| 30 |
if *url == "" { |
| 31 |
*url = "http://127.0.0.1:9200" |
| 32 |
} |
| 33 |
|
| 34 |
// Create an Elasticsearch client |
| 35 |
client, err := elastic.NewClient(elastic.SetURL(*url), elastic.SetSniff(*sniff)) |
| 36 |
if err != nil { |
| 37 |
log.Fatal(err) |
| 38 |
} |
| 39 |
_ = client |
| 40 |
|
| 41 |
// Just a status message |
| 42 |
fmt.Println("Connection succeeded") |
| 43 |
} |