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 @@ -187,6 +187,7 @@ import (
187187 " strconv"
188188 " strings"
189189 " sync"
190+ " bytes"
190191
191192 " github.com/elastic/go-elasticsearch/v7"
192193 " github.com/elastic/go-elasticsearch/v7/esapi"
@@ -237,17 +238,17 @@ func main() {
237238 go func (i int , title string ) {
238239 defer wg.Done ()
239240
240- // Build the request body.
241- var b strings. Builder
242- b. WriteString ( ` {"title" : " ` )
243- b. WriteString (title )
244- b. WriteString ( ` "} ` )
241+ // Build the request body.
242+ data , err := json. Marshal ( struct { Title string }{Title: title})
243+ if err != nil {
244+ log. Fatalf ( " Error marshaling document: %s " , err )
245+ }
245246
246247 // Set up the request object.
247248 req := esapi.IndexRequest {
248249 Index: " test" ,
249250 DocumentID: strconv.Itoa (i + 1 ),
250- Body: strings .NewReader (b. String () ),
251+ Body: bytes .NewReader (data ),
251252 Refresh: " true" ,
252253 }
253254
You can’t perform that action at this time.
0 commit comments