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

Function init

_benchmarks/benchmarks/actions/004_index.go:34–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32)
33
34func init() {
35 benchmarks.Register(
36 benchmarks.Action{
37 Name: "index",
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-index"
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.Indices.Create(indexName)
54 if err != nil {
55 return res, err
56 }
57 if res.Body != nil {
58 io.Copy(ioutil.Discard, res.Body)
59 res.Body.Close()
60 }
61 return res, err
62 },
63 RunnerFunc: func(n int, c runner.Config) (*esapi.Response, error) {
64 var (
65 res *esapi.Response
66 err error
67
68 indexName = "test-bench-index"
69 )
70
71 docID := fmt.Sprintf("%04d-%04d", n, rand.Intn(benchmarks.DefaultRepetitions))
72 docBody := bytes.NewBuffer(benchmarks.DataSources["small"].Bytes())
73 res, err = c.RunnerClient.Index(indexName, docBody, c.RunnerClient.Index.WithDocumentID(docID))
74 if err != nil {
75 return res, err
76 }
77
78 var b bytes.Buffer
79 if _, err := b.ReadFrom(res.Body); err != nil {
80 return nil, err
81 }
82 res.Body.Close()
83
84 output := gjson.GetBytes(b.Bytes(), "result")
85 if output.Str != "created" {
86 return nil, fmt.Errorf("Unexpected output: %s", b.String())
87 }
88 return res, err
89 },
90 },
91 )

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.65
DeleteMethod · 0.45
CreateMethod · 0.45
BytesMethod · 0.45
IndexMethod · 0.45
WithDocumentIDMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected