我想使用 Go 包 elastic
中的 BulkIndexRequest
。我试图找到例子,但似乎它们不存在。所以如果有人用过它,你能帮我用它来创建像下面这样的请求吗?
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"}
'
最佳答案
您可以在 test classes 中找到一些示例很好explained in the wiki .它是这样的:
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)
}
...
关于elasticsearch - 使用 golang 包 'elastic' 中的 BulkIndexRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45326078/