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

Function main

_examples/bulk/default.go:79–302  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

77}
78
79func main() {
80 log.SetFlags(0)
81
82 type bulkResponse struct {
83 Errors bool `json:"errors"`
84 Items []struct {
85 Index struct {
86 ID string `json:"_id"`
87 Result string `json:"result"`
88 Status int `json:"status"`
89 Error struct {
90 Type string `json:"type"`
91 Reason string `json:"reason"`
92 Cause struct {
93 Type string `json:"type"`
94 Reason string `json:"reason"`
95 } `json:"caused_by"`
96 } `json:"error"`
97 } `json:"index"`
98 } `json:"items"`
99 }
100
101 var (
102 buf bytes.Buffer
103 res *esapi.Response
104 err error
105 raw map[string]interface{}
106 blk *bulkResponse
107
108 articles []*Article
109 indexName = "articles"
110
111 numItems int
112 numErrors int
113 numIndexed int
114 numBatches int
115 currBatch int
116 )
117
118 log.Printf(
119 "\x1b[1mBulk\x1b[0m: documents [%s] batch size [%s]",
120 humanize.Comma(int64(count)), humanize.Comma(int64(batch)))
121 log.Println(strings.Repeat("▁", 65))
122
123 // Create the Elasticsearch client
124 //
125 es, err := elasticsearch.New()
126 if err != nil {
127 log.Fatalf("Error creating the client: %s", err)
128 }
129 defer func() {
130 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
131 defer cancel()
132 if err := es.Close(ctx); err != nil {
133 log.Fatalf("Error closing the client: %s", err)
134 }
135 }()
136

Callers

nothing calls this directly

Calls 12

PrintfMethod · 0.80
JoinMethod · 0.80
IsErrorMethod · 0.80
CloseMethod · 0.65
WithTimeoutMethod · 0.45
DeleteMethod · 0.45
CreateMethod · 0.45
WriteMethod · 0.45
BulkMethod · 0.45
BytesMethod · 0.45
WithIndexMethod · 0.45
TruncateMethod · 0.45

Tested by

no test coverage detected