Repository: opensearch-project/opensearch-go
Pull request #166 (2022-09-30 19:23:02)

Replaced if_seq_num to if_seq_no
Signed-off by: Kyle Darryl Aguilar <aguilarkyledarryl@gmail.com>

### Description
Renamed the sequence number struct tag to resolve issues when performing optimistic concurrency control

### Issues Resolved
Resolves https://github.com/opensearch-project/opensearch-go/issues/165

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: Please amend the commit with `-s` (DCO).

Is this something we can/should have a unit test for?
noname4life: Thank you for the review and noted on this. I have amended the commit and have added a unit test for this change.
dblock: Something's off with CI/CD 🤔 
noname4life: It seems to have been caused by certain configurations in my local. Updated the commit to address this.
noname4life: Hi @dblock , the failing linter seems to be caused by the go version 1.16.2 in the [lint.yml](https://github.com/opensearch-project/opensearch-go/blob/main/.github/workflows/lint.yml#L23) file in reference to the [returned error](https://github.com/opensearch-project/opensearch-go/actions/runs/3191425269/jobs/5428591319) of the lint github action which indicated a required go version of 1.17.

I have tried pushing a commit which bumps this go-version of the lint.yml file to 1.17. However, I have a received the following error while doing so:
` ! [remote rejected] fix-seq-num -> fix-seq-num (refusing to allow a Personal Access Token to create or update workflow `.github/workflows/lint.yml` without `workflow` scope)`

Kindly let me know what are the next steps that I should take regarding this. Thank you!
VachaShah: Hi @noname4life, can you please rebase to get the latest changes from main? Thank you!
noname4life: Hi @VachaShah, I have rebased this branch with the updates from main. Kindly let me know if I have missed anything. Thank you!
noname4life: Hi @dblock @VachaShah , I have added an entry in CHANGELOG
VachaShah: > Hi @dblock @VachaShah , I have added an entry in CHANGELOG

Thank you @noname4life, re-running the workflows

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5d0110e..b941e21 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
 ### Removed
 
 ### 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))
 
 ### Security
 
diff --git a/USER_GUIDE.md b/USER_GUIDE.md
index 05a2106..727e0eb 100644
--- a/USER_GUIDE.md
+++ b/USER_GUIDE.md
@@ -46,12 +46,12 @@ func main() {
 
 	// Define index mapping.
 	mapping := strings.NewReader(`{
-     'settings': {
-       'index': {
-            'number_of_shards': 4
-            }
-          }
-     }`)
+	    "settings": {
+	        "index": {
+	            "number_of_shards": 4
+	        }
+	    }
+	}`)
 
 	// Create an index with non-default settings.
 	createIndex := opensearchapi.IndicesCreateRequest{
@@ -67,10 +67,10 @@ func main() {
 
 	// Add a document to the index.
 	document := strings.NewReader(`{
-        "title": "Moneyball",
-        "director": "Bennett Miller",
-        "year": "2011"
-    }`)
+	    "title": "Moneyball",
+	    "director": "Bennett Miller",
+	    "year": "2011"
+	}`)
 
 	docId := "1"
 	req := opensearchapi.IndexRequest{
@@ -87,14 +87,14 @@ func main() {
 
 	// Search for the document.
 	content := strings.NewReader(`{
-       "size": 5,
-       "query": {
-           "multi_match": {
-           "query": "miller",
-           "fields": ["title^2", "director"]
-           }
-      }
-    }`)
+	    "size": 5,
+	    "query": {
+	        "multi_match": {
+	            "query": "miller",
+	            "fields": ["title^2", "director"]
+	        }
+	    }
+	}`)
 
 	search := opensearchapi.SearchRequest{
 		Body: content,
diff --git a/opensearchutil/bulk_indexer.go b/opensearchutil/bulk_indexer.go
index 3f08cec..f56ceac 100644
--- a/opensearchutil/bulk_indexer.go
+++ b/opensearchutil/bulk_indexer.go
@@ -133,7 +133,7 @@ type bulkActionMetadata struct {
 	Routing             *string     `json:"routing,omitempty"`
 	Version             *int64      `json:"version,omitempty"`
 	VersionType         *string     `json:"version_type,omitempty"`
-	IfSeqNum            *int64      `json:"if_seq_num,omitempty"`
+	IfSeqNum            *int64      `json:"if_seq_no,omitempty"`
 	IfPrimaryTerm       *int64      `json:"if_primary_term,omitempty"`
 	WaitForActiveShards interface{} `json:"wait_for_active_shards,omitempty"`
 	Refresh             *string     `json:"refresh,omitempty"`


Test patch:
diff --git a/opensearchutil/bulk_indexer_internal_test.go b/opensearchutil/bulk_indexer_internal_test.go
index a5c909b..ff8539d 100644
--- a/opensearchutil/bulk_indexer_internal_test.go
+++ b/opensearchutil/bulk_indexer_internal_test.go
@@ -678,7 +678,18 @@ func TestBulkIndexer(t *testing.T) {
 				`{"index":{"_index":"test","_id":"42"}}` + "\n",
 			},
 			{
-				"with version and no document",
+				"with if_seq_no and if_primary_term",
+				args{BulkIndexerItem{
+					Action:        "index",
+					DocumentID:    "42",
+					Index:         "test",
+					IfSeqNum:      int64Pointer(5),
+					IfPrimaryTerm: int64Pointer(1),
+				}},
+				`{"index":{"_index":"test","_id":"42","if_seq_no":5,"if_primary_term":1}}` + "\n",
+			},
+			{
+				"with version and no document, if_seq_no, and if_primary_term",
 				args{BulkIndexerItem{
 					Action:  "index",
 					Index:   "test",