MCPcopy
hub / github.com/elastic/go-elasticsearch / run

Function run

_examples/logging/default.go:93–128  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------

(es *elasticsearch.Client, name string)

Source from the content-addressed store, hash-verified

91// ------------------------------------------------------------------------------------------------
92
93func 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}

Callers 1

mainFunction · 0.85

Calls 12

DeleteMethod · 0.45
ExistsMethod · 0.45
IndexMethod · 0.45
WithRefreshMethod · 0.45
WithPrettyMethod · 0.45
WithFilterPathMethod · 0.45
SearchMethod · 0.45
WithQueryMethod · 0.45
WithIndexMethod · 0.45
WithBodyMethod · 0.45
WithSizeMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected