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

Function init

_benchmarks/benchmarks/actions/003_get.go:34–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32)
33
34func init() {
35 benchmarks.Register(
36 benchmarks.Action{
37 Name: "get",
38 Category: "core",
39 NumWarmups: 100,
40 NumRepetitions: 10000,
41 SetupFunc: func(n int, c runner.Config) (*esapi.Response, error) {
42 var (
43 res *esapi.Response
44 err error
45
46 indexName = "test-bench-get"
47 )
48 res, _ = c.RunnerClient.Indices.Delete([]string{indexName})
49 if res != nil && res.Body != nil {
50 io.Copy(ioutil.Discard, res.Body)
51 res.Body.Close()
52 }
53 res, err = c.RunnerClient.Index(indexName, strings.NewReader(`{"title":"Test"}`), c.RunnerClient.Index.WithDocumentID("1"))
54 if err != nil {
55 return res, err
56 }
57 defer res.Body.Close()
58 io.Copy(ioutil.Discard, res.Body)
59 res, err = c.RunnerClient.Indices.Refresh(c.RunnerClient.Indices.Refresh.WithIndex(indexName))
60 if err != nil {
61 return res, err
62 }
63 io.Copy(ioutil.Discard, res.Body)
64 res.Body.Close()
65 return res, err
66 },
67 RunnerFunc: func(n int, c runner.Config) (*esapi.Response, error) {
68 var indexName = "test-bench-get"
69 res, err := c.RunnerClient.Get(indexName, "1")
70 if err != nil {
71 return res, err
72 }
73 var b bytes.Buffer
74 if _, err := b.ReadFrom(res.Body); err != nil {
75 return nil, err
76 }
77 res.Body.Close()
78
79 output := gjson.GetBytes(b.Bytes(), "_source.title")
80 if output.Str != "Test" {
81 return nil, fmt.Errorf("Unexpected output: %q", b.String())
82 }
83 return res, err
84 },
85 },
86 )
87}

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.65
DeleteMethod · 0.45
IndexMethod · 0.45
WithDocumentIDMethod · 0.45
RefreshMethod · 0.45
WithIndexMethod · 0.45
GetMethod · 0.45
BytesMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected