()
| 33 | } |
| 34 | |
| 35 | func main() { |
| 36 | var ( |
| 37 | res *esapi.Response |
| 38 | err error |
| 39 | ) |
| 40 | |
| 41 | es, err := elasticsearch.New() |
| 42 | if err != nil { |
| 43 | log.Fatalf("Error creating the client: %s", err) |
| 44 | } |
| 45 | defer func() { |
| 46 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 47 | defer cancel() |
| 48 | if err := es.Close(ctx); err != nil { |
| 49 | fmt.Printf("Error closing the client: %s\n", err) |
| 50 | } |
| 51 | }() |
| 52 | |
| 53 | doc := struct { |
| 54 | Title string `json:"title"` |
| 55 | }{Title: "Test"} |
| 56 | |
| 57 | res, err = es.Index("test", esutil.NewJSONReader(&doc), es.Index.WithRefresh("true")) |
| 58 | if err != nil { |
| 59 | log.Fatalf("Error getting response: %s", err) |
| 60 | } |
| 61 | |
| 62 | log.Println(res) |
| 63 | |
| 64 | query := map[string]interface{}{ |
| 65 | "query": map[string]interface{}{ |
| 66 | "match": map[string]interface{}{ |
| 67 | "title": "test", |
| 68 | }, |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | res, err = es.Search( |
| 73 | es.Search.WithIndex("test"), |
| 74 | es.Search.WithBody(esutil.NewJSONReader(&query)), |
| 75 | es.Search.WithPretty(), |
| 76 | ) |
| 77 | if err != nil { |
| 78 | log.Fatalf("Error getting response: %s", err) |
| 79 | } |
| 80 | |
| 81 | log.Println(res) |
| 82 | } |
nothing calls this directly
no test coverage detected