I can insert the data into elasticsearch using olivere, but if I want to add more data into existing index that has been created before, it won't work.
This is the code
package main
import (
"context"
"fmt"
"strconv"
"github.com/olivere/elastic"
)
type Tweet struct {
User string `json:"user"`
Message string `json:"message"`
}
func main() {
client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
if err != nil {
fmt.Println("%v", err)
}
n := 0
for i := 0; i < 1000; i++ {
bulkRequest := client.Bulk()
for j := 0; j < 10000; j++ {
n++
tweet := Tweet{User: "Markus", Message: "This is the new from string representations of basic data types. " + strconv.Itoa(n)}
req :=
elastic.NewBulkIndexRequest().Index("twitwar").Type("tweet").Id(strconv.Itoa(n)).Doc(tweet)
bulkRequest.Add(req)
}
bulkResponse, err := bulkRequest.Do(context.Background())
if err != nil {
fmt.Println(err)
}
if bulkResponse != nil {
fmt.Println("Data have been inserted", i)
}
fmt.Println("I", i)
}
}
How can I add more data into index that has been defined before?
Thanks
Comments
Post a Comment