------------------------------------------------------------------------------------------------
(es *elasticsearch.Client, name string)
| 91 | // ------------------------------------------------------------------------------------------------ |
| 92 | |
| 93 | func run(es *elasticsearch.Client, name string) { |
| 94 | log.Println("███", fmt.Sprintf("\x1b[1m%s\x1b[0m", name), strings.Repeat("█", 75-len(name))) |
| 95 | |
| 96 | es.Delete("test", "1") |
| 97 | es.Exists("test", "1") |
| 98 | |
| 99 | es.Index( |
| 100 | "test", |
| 101 | strings.NewReader(`{"title" : "logging"}`), |
| 102 | es.Index.WithRefresh("true"), |
| 103 | es.Index.WithPretty(), |
| 104 | es.Index.WithFilterPath("result", "_id"), |
| 105 | ) |
| 106 | |
| 107 | es.Search(es.Search.WithQuery("{FAIL")) |
| 108 | |
| 109 | res, err := es.Search( |
| 110 | es.Search.WithIndex("test"), |
| 111 | es.Search.WithBody(strings.NewReader(`{"query" : {"match" : { "title" : "logging" } } }`)), |
| 112 | es.Search.WithSize(1), |
| 113 | es.Search.WithPretty(), |
| 114 | es.Search.WithFilterPath("took", "hits.hits"), |
| 115 | ) |
| 116 | |
| 117 | s := res.String() |
| 118 | // log.Println("\x1b[1mResponse:\x1b[0m", s) |
| 119 | if len(s) <= len("[200 OK] ") { |
| 120 | log.Fatal("Response body is empty") |
| 121 | } |
| 122 | |
| 123 | if err != nil { |
| 124 | log.Fatalf("Error: %s", err) |
| 125 | } |
| 126 | |
| 127 | log.Print("\n") |
| 128 | } |
no test coverage detected