I want to use BulkIndexRequest
from Go package elastic
. I try to find examples but it seems that they don't exist. So if anybody has used it, could you please help me to use it for creating request something like below?
curl -s -H "Content-Type: application/json" -XPOST localhost:9200/someindex/sometype/_bulk -d'
{ "index": {"_id": "existing_id"}}
{ "field1": "test1"}
{ "index": {"_id": "existing_id2"}}
{ "field2": "test2"}
'
You can find a few examples in the test classes and is pretty well explained in the wiki. It goes like this:
indexName := "someindex"
typeName := "sometype"
index1Req := NewBulkIndexRequest().Index(indexName).Type(typeName).Id("existing_id").Doc({...})
index2Req := NewBulkIndexRequest().Index(indexName).Type(typeName).Id("existing_id2").Doc({...})
bulkRequest := client.Bulk()
bulkRequest = bulkRequest.Add(index1Req)
bulkRequest = bulkRequest.Add(index2Req)
bulkResponse, err := bulkRequest.Do(context.TODO())
if err != nil {
t.Fatal(err)
}
...