Skip to content

Commit

Permalink
replace readme string concat with json marshal (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
epelc authored and Anaethelion committed May 12, 2022
1 parent 4f482c7 commit 57af57e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ import (
"strconv"
"strings"
"sync"
"bytes"

"github.com/elastic/go-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7/esapi"
Expand Down Expand Up @@ -237,17 +238,17 @@ func main() {
go func(i int, title string) {
defer wg.Done()

// Build the request body.
var b strings.Builder
b.WriteString(`{"title" : "`)
b.WriteString(title)
b.WriteString(`"}`)
// Build the request body.
data, err := json.Marshal(struct{ Title string }{Title: title})
if err != nil {
log.Fatalf("Error marshaling document: %s", err)
}

// Set up the request object.
req := esapi.IndexRequest{
Index: "test",
DocumentID: strconv.Itoa(i + 1),
Body: strings.NewReader(b.String()),
Body: bytes.NewReader(data),
Refresh: "true",
}

Expand Down

0 comments on commit 57af57e

Please sign in to comment.