Skip to content

Commit

Permalink
Change _retry_on_conflict to retry_on_conflict
Browse files Browse the repository at this point in the history
Elasticsearch version 6.0 used the version with a leading underscore,
while 6.1 and later use the one without. With elastic 6.1+ we settle
for the latter.

See #662
  • Loading branch information
olivere committed Dec 27, 2017
1 parent 36c8ae5 commit a2982a5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bulk_index_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func (r *BulkIndexRequest) Source() ([]string, error) {
indexCommand["_version_type"] = r.versionType
}
if r.retryOnConflict != nil {
indexCommand["_retry_on_conflict"] = *r.retryOnConflict
// It's _retry_on_conflict for 6.0 and retry_on_conflict for 6.1+
indexCommand["retry_on_conflict"] = *r.retryOnConflict
}
if r.ttl != "" {
indexCommand["_ttl"] = r.ttl
Expand Down
2 changes: 1 addition & 1 deletion bulk_index_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestBulkIndexRequestSerialization(t *testing.T) {
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("doc").Id("1").RetryOnConflict(42).
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
Expected: []string{
`{"index":{"_id":"1","_index":"index1","_retry_on_conflict":42,"_type":"doc"}}`,
`{"index":{"_id":"1","_index":"index1","_type":"doc","retry_on_conflict":42}}`,
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
},
},
Expand Down
3 changes: 2 additions & 1 deletion bulk_update_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ func (r *BulkUpdateRequest) Source() ([]string, error) {
updateCommand["_version_type"] = r.versionType
}
if r.retryOnConflict != nil {
updateCommand["_retry_on_conflict"] = *r.retryOnConflict
// It's _retry_on_conflict for 6.0 and retry_on_conflict for 6.1+
updateCommand["retry_on_conflict"] = *r.retryOnConflict
}
command["update"] = updateCommand
line, err := json.Marshal(command)
Expand Down
6 changes: 3 additions & 3 deletions bulk_update_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
Counter: 42,
}),
Expected: []string{
`{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"doc"}}`,
`{"update":{"_id":"1","_index":"index1","_type":"doc","retry_on_conflict":3}}`,
`{"doc":{"counter":42},"doc_as_upsert":true}`,
},
},
Expand All @@ -51,7 +51,7 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
Counter: 42,
}),
Expected: []string{
`{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"doc"}}`,
`{"update":{"_id":"1","_index":"index1","_type":"doc","retry_on_conflict":3}}`,
`{"script":{"lang":"javascript","params":{"param1":42},"source":"ctx._source.retweets += param1"},"upsert":{"counter":42}}`,
},
},
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestBulkUpdateRequestSerialization(t *testing.T) {
Counter: 42,
}),
Expected: []string{
`{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"doc"}}`,
`{"update":{"_id":"1","_index":"index1","_type":"doc","retry_on_conflict":3}}`,
`{"script":{"lang":"javascript","params":{"param1":42},"source":"ctx._source.retweets += param1"},"scripted_upsert":true,"upsert":{"counter":42}}`,
},
},
Expand Down

0 comments on commit a2982a5

Please sign in to comment.