Repository: opensearch-project/opensearch-go
Pull request #215 (2023-01-17 11:20:50)

bugfix: adjusts to use retry_on_conflict on bulk
### Description

Bug fix.

Adjust to set `retry_on_conflict` when using bulk indexer.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check [here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).


dblock: Thank you! Can you please add a unit test for this, since we've visibly introduced a bug?
nicolascb: hello @dblock,

I added a unit test for this case, can you review again please?
nicolascb: @dblock done =D

Patch:
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 7d62bd6..890116d 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1,2 +1,2 @@
 # This should match the team set up in https://github.com/orgs/opensearch-project/teams and include any additional contributors
-*   @opensearch-project/clients @svencowart @robcowart
\ No newline at end of file
+*   @dblock @VijayanB @svencowart @VachaShah
\ No newline at end of file
diff --git a/.github/workflows/dependabot_pr.yml b/.github/workflows/dependabot_pr.yml
index a6c8a69..3acba18 100644
--- a/.github/workflows/dependabot_pr.yml
+++ b/.github/workflows/dependabot_pr.yml
@@ -1,5 +1,12 @@
 name: Dependabot PR actions
-on: pull_request
+on: 
+  pull_request:
+    types:
+      - opened
+      - reopened
+      - synchronize
+      - labeled
+      - unlabeled
 
 jobs:
   dependabot:
@@ -18,7 +25,7 @@ jobs:
           installation_id: 22958780
 
       - name: Check out code
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
         with:
           token: ${{ steps.github_app_token.outputs.token }}
 
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9352ddf..ff1f14e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
 ### Dependencies
 - Bumps `github.com/aws/aws-sdk-go-v2` from 1.17.1 to 1.17.3
 - Bumps `github.com/aws/aws-sdk-go-v2/config` from 1.17.10 to 1.18.8
-- Bumps `github.com/aws/aws-sdk-go` from 1.44.132 to 1.44.176
+- Bumps `github.com/aws/aws-sdk-go` from 1.44.176 to 1.44.180
+- Bumps `github.com/aws/aws-sdk-go` from 1.44.132 to 1.44.180
 
 ### Added
 - Github workflow for changelog verification ([#172](https://github.com/opensearch-project/opensearch-go/pull/172))
@@ -23,8 +24,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
 
 ### Fixed
  - Renamed the sequence number struct tag to if_seq_no to fix optimistic concurrency control ([#166](https://github.com/opensearch-project/opensearch-go/pull/166))
+ - Fix `RetryOnConflict` on bulk indexer ([#215](https://github.com/opensearch-project/opensearch-go/pull/215))
 
 ### Security
 
 
-[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/2.1...HEAD
\ No newline at end of file
+[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/2.1...HEAD
diff --git a/MAINTAINERS.md b/MAINTAINERS.md
index 55728dc..9f4480b 100644
--- a/MAINTAINERS.md
+++ b/MAINTAINERS.md
@@ -6,14 +6,15 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
 
 | Maintainer              | GitHub ID                                   | Affiliation |
 | ----------------------- | ------------------------------------------- | ----------- |
-| Jack Mazanec            | [jmazanec15](https://github.com/jmazanec15) | Amazon      |
-| Vamshi Vijay Nakkirtha  | [vamshin](https://github.com/vamshin)       | Amazon      |
+| Daniel Doubrovkine      | [dblock](https://github.com/dblock)         | Amazon      |
 | Vijayan Balasubramanian | [VijayanB](https://github.com/VijayanB)     | Amazon      |
 | Sven Cowart             | [svencowart](https://github.com/svencowart) |             |
 | Vacha Shah              | [VachaShah](https://github.com/VachaShah)   | Amazon      |
 
 ## Emeritus
 
-| Maintainer | GitHub ID                                 | Affiliation |
-| ---------- | ----------------------------------------- | ----------- |
-| Rob Cowart | [robcowart](https://github.com/robcowart) | ElastiFlow  |
+| Maintainer              | GitHub ID                                   | Affiliation |
+| ----------------------- | ------------------------------------------- | ----------- |
+| Jack Mazanec            | [jmazanec15](https://github.com/jmazanec15) | Amazon      |
+| Vamshi Vijay Nakkirtha  | [vamshin](https://github.com/vamshin)       | Amazon      |
+| Rob Cowart              | [robcowart](https://github.com/robcowart)   | ElastiFlow  |
diff --git a/go.mod b/go.mod
index 05e244f..399c2ba 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/opensearch-project/opensearch-go/v2
 go 1.15
 
 require (
-	github.com/aws/aws-sdk-go v1.44.176
+	github.com/aws/aws-sdk-go v1.44.180
 	github.com/aws/aws-sdk-go-v2 v1.17.3
 	github.com/aws/aws-sdk-go-v2/config v1.18.8
 	github.com/stretchr/testify v1.8.1
diff --git a/go.sum b/go.sum
index 08fe650..ec590da 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/aws/aws-sdk-go v1.44.176 h1:mxcfI3IWHemX+5fEKt5uqIS/hdbaR7qzGfJYo5UyjJE=
-github.com/aws/aws-sdk-go v1.44.176/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
+github.com/aws/aws-sdk-go v1.44.180 h1:VLZuAHI9fa/3WME5JjpVjcPCNfpGHVMiHx8sLHWhMgI=
+github.com/aws/aws-sdk-go v1.44.180/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/aws/aws-sdk-go-v2 v1.17.3 h1:shN7NlnVzvDUgPQ+1rLMSxY8OWRNDRYtiqe0p/PgrhY=
 github.com/aws/aws-sdk-go-v2 v1.17.3/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
 github.com/aws/aws-sdk-go-v2/config v1.18.8 h1:lDpy0WM8AHsywOnVrOHaSMfpaiV2igOw8D7svkFkXVA=
diff --git a/opensearchutil/bulk_indexer.go b/opensearchutil/bulk_indexer.go
index f56ceac..0ed320a 100644
--- a/opensearchutil/bulk_indexer.go
+++ b/opensearchutil/bulk_indexer.go
@@ -138,6 +138,7 @@ type bulkActionMetadata struct {
 	WaitForActiveShards interface{} `json:"wait_for_active_shards,omitempty"`
 	Refresh             *string     `json:"refresh,omitempty"`
 	RequireAlias        *bool       `json:"require_alias,omitempty"`
+	RetryOnConflict     *int        `json:"retry_on_conflict,omitempty"`
 }
 
 // BulkIndexerResponse represents the OpenSearch response.
@@ -447,6 +448,7 @@ func (w *worker) writeMeta(item BulkIndexerItem) error {
 		WaitForActiveShards: item.WaitForActiveShards,
 		Refresh:             item.Refresh,
 		RequireAlias:        item.RequireAlias,
+		RetryOnConflict:     item.RetryOnConflict,
 	}
 	// Can not specify version or seq num if no document ID is passed
 	if meta.DocumentID == "" {


Test patch:
diff --git a/opensearchutil/bulk_indexer_internal_test.go b/opensearchutil/bulk_indexer_internal_test.go
index ff8539d..705f7d2 100644
--- a/opensearchutil/bulk_indexer_internal_test.go
+++ b/opensearchutil/bulk_indexer_internal_test.go
@@ -742,6 +742,18 @@ func TestBulkIndexer(t *testing.T) {
 				}},
 				`{"index":{"_index":"test","_id":"42","version":25,"version_type":"external","wait_for_active_shards":"all"}}` + "\n",
 			},
+			{
+				"with retry_on_conflict",
+				args{BulkIndexerItem{
+					Action:          "index",
+					DocumentID:      "42",
+					Index:           "test",
+					Version:         int64Pointer(25),
+					VersionType:     strPointer("external"),
+					RetryOnConflict: intPointer(5),
+				}},
+				`{"index":{"_index":"test","_id":"42","version":25,"version_type":"external","retry_on_conflict":5}}` + "\n",
+			},
 		}
 		for _, tt := range tests {
 			tt := tt
@@ -777,3 +789,7 @@ func strPointer(s string) *string {
 func int64Pointer(i int64) *int64 {
 	return &i
 }
+
+func intPointer(i int) *int {
+	return &i
+}