File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,7 @@ import (
196196 " strconv"
197197 " strings"
198198 " sync"
199+ " bytes"
199200
200201 " github.com/elastic/go-elasticsearch/v8"
201202 " github.com/elastic/go-elasticsearch/v8/esapi"
@@ -246,17 +247,17 @@ func main() {
246247 go func (i int , title string ) {
247248 defer wg.Done ()
248249
249- // Build the request body.
250- var b strings. Builder
251- b. WriteString ( ` {"title" : " ` )
252- b. WriteString (title )
253- b. WriteString ( ` "} ` )
250+ // Build the request body.
251+ data , err := json. Marshal ( struct { Title string }{Title: title})
252+ if err != nil {
253+ log. Fatalf ( " Error marshaling document: %s " , err )
254+ }
254255
255256 // Set up the request object.
256257 req := esapi.IndexRequest {
257258 Index: " test" ,
258259 DocumentID: strconv.Itoa (i + 1 ),
259- Body: strings .NewReader (b. String () ),
260+ Body: bytes .NewReader (data ),
260261 Refresh: " true" ,
261262 }
262263
You can’t perform that action at this time.
0 commit comments