summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go')
-rw-r--r--vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go60
1 files changed, 44 insertions, 16 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go
index afe873890..53e73bd40 100644
--- a/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go
+++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_test.go
@@ -15,19 +15,20 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
}{
// #0
{
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").Doc(struct {
+ Request: NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").Doc(struct {
Counter int64 `json:"counter"`
}{
Counter: 42,
}),
Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_type":"tweet"}}`,
+ `{"update":{"_index":"index1","_type":"doc","_id":"1"}}`,
`{"doc":{"counter":42}}`,
},
},
// #1
{
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").
+ Request: NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").
+ Routing("123").
RetryOnConflict(3).
DocAsUpsert(true).
Doc(struct {
@@ -36,13 +37,13 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
Counter: 42,
}),
Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"tweet"}}`,
+ `{"update":{"_index":"index1","_type":"doc","_id":"1","retry_on_conflict":3,"routing":"123"}}`,
`{"doc":{"counter":42},"doc_as_upsert":true}`,
},
},
// #2
{
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").
+ Request: NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").
RetryOnConflict(3).
Script(NewScript(`ctx._source.retweets += param1`).Lang("javascript").Param("param1", 42)).
Upsert(struct {
@@ -51,25 +52,25 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
Counter: 42,
}),
Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"tweet"}}`,
- `{"script":{"inline":"ctx._source.retweets += param1","lang":"javascript","params":{"param1":42}},"upsert":{"counter":42}}`,
+ `{"update":{"_index":"index1","_type":"doc","_id":"1","retry_on_conflict":3}}`,
+ `{"script":{"lang":"javascript","params":{"param1":42},"source":"ctx._source.retweets += param1"},"upsert":{"counter":42}}`,
},
},
// #3
{
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").DetectNoop(true).Doc(struct {
+ Request: NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").DetectNoop(true).Doc(struct {
Counter int64 `json:"counter"`
}{
Counter: 42,
}),
Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_type":"tweet"}}`,
+ `{"update":{"_index":"index1","_type":"doc","_id":"1"}}`,
`{"detect_noop":true,"doc":{"counter":42}}`,
},
},
// #4
{
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").
+ Request: NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").
RetryOnConflict(3).
ScriptedUpsert(true).
Script(NewScript(`ctx._source.retweets += param1`).Lang("javascript").Param("param1", 42)).
@@ -79,8 +80,20 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
Counter: 42,
}),
Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"tweet"}}`,
- `{"script":{"inline":"ctx._source.retweets += param1","lang":"javascript","params":{"param1":42}},"scripted_upsert":true,"upsert":{"counter":42}}`,
+ `{"update":{"_index":"index1","_type":"doc","_id":"1","retry_on_conflict":3}}`,
+ `{"script":{"lang":"javascript","params":{"param1":42},"source":"ctx._source.retweets += param1"},"scripted_upsert":true,"upsert":{"counter":42}}`,
+ },
+ },
+ // #5
+ {
+ Request: NewBulkUpdateRequest().Index("index1").Type("doc").Id("4").ReturnSource(true).Doc(struct {
+ Counter int64 `json:"counter"`
+ }{
+ Counter: 42,
+ }),
+ Expected: []string{
+ `{"update":{"_index":"index1","_type":"doc","_id":"4"}}`,
+ `{"doc":{"counter":42},"_source":true}`,
},
},
}
@@ -107,15 +120,30 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
var bulkUpdateRequestSerializationResult string
func BenchmarkBulkUpdateRequestSerialization(b *testing.B) {
- r := NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").Doc(struct {
- Counter int64 `json:"counter"`
- }{
- Counter: 42,
+ b.Run("stdlib", func(b *testing.B) {
+ r := NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").Doc(struct {
+ Counter int64 `json:"counter"`
+ }{
+ Counter: 42,
+ })
+ benchmarkBulkUpdateRequestSerialization(b, r.UseEasyJSON(false))
})
+ b.Run("easyjson", func(b *testing.B) {
+ r := NewBulkUpdateRequest().Index("index1").Type("doc").Id("1").Doc(struct {
+ Counter int64 `json:"counter"`
+ }{
+ Counter: 42,
+ }).UseEasyJSON(false)
+ benchmarkBulkUpdateRequestSerialization(b, r.UseEasyJSON(true))
+ })
+}
+
+func benchmarkBulkUpdateRequestSerialization(b *testing.B, r *BulkUpdateRequest) {
var s string
for n := 0; n < b.N; n++ {
s = r.String()
r.source = nil // Don't let caching spoil the benchmark
}
bulkUpdateRequestSerializationResult = s // ensure the compiler doesn't optimize
+ b.ReportAllocs()
}