I have been unable to find an example for opensearch-go client to trigger a bulk request. The docs just point to the regular API call instead.
Can someone help with it. A bulk index request.
Hi @vikaslalwani ,
I will create an issue in github repo to include an example. In the meantime, you can try something like below
func main() {
// Create the OpenSearch client
//
// Initialize the client with SSL/TLS enabled.
client, err := opensearch.NewClient(opensearch.Config{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // For testing only. Use certificate for validation.
},
Addresses: []string{"https://localhost:9200"},
Username: "admin", // For testing only. Don't store credentials in code.
Password: "admin",
})
if err != nil {
fmt.Println("cannot initialize", err)
os.Exit(1)
}
res, err := client.Bulk(
strings.NewReader(`
{ "index" : { "_index" : "example_index", "_id" : "1" } }
{ "x" : "1", "y" : "2" }
{ "create" : { "_index" : "example_index", "_id" : "3" } }
{ "x" : "3", "y" : "4" }
{ "update" : {"_id" : "1", "_index" : "example_index"} }
{ "doc" : {"x" : "-1"} }
`),
)
fmt.Println(res, err)
}
I hope it helps.
@Vijay Thanks. So there’s no clean way to create a bulk
object and just do a bulk.add(payload1)
bulk.add(payload2) ...and so on
incrementally before we trigger the bulk publish to Opensearch?
@vikaslalwani You can try BulkIndexer opensearch-go/bulk_indexer.go at 1.1 · opensearch-project/opensearch-go · GitHub
1 Like