diff --git a/es.go b/es.go index 3def58c..7f6d20d 100644 --- a/es.go +++ b/es.go @@ -1186,19 +1186,19 @@ func (c *Client) SnapshotAllIndicesWithBodyParams(repository string, snapshot st return errors.New("empty string for snapshot is not allowed") } - if bodyParams == nil { - return errors.New("no body params provided, please use SnapshotAllIndices Function instead") - } - parsedJSON, parsingErr := json.Marshal(bodyParams) if parsingErr != nil { return parsingErr } - agent := c.buildPutRequest(fmt.Sprintf("_snapshot/%s/%s", repository, snapshot)). - Set("Content-Type", "application/json"). - Send(string(parsedJSON)) + agent := c.buildPutRequest(fmt.Sprintf("_snapshot/%s/%s", repository, snapshot)) + + if bodyParams != nil { + agent = agent. + Set("Content-Type", "application/json"). + Send(string(parsedJSON)) + } _, err := handleErrWithBytes(agent) diff --git a/es_test.go b/es_test.go index fc135b0..7fc3d4c 100644 --- a/es_test.go +++ b/es_test.go @@ -1430,11 +1430,10 @@ func TestSnapshotAllIndicesWithAdditionalParametersIncludeGlobalState(t *testing } } -func TestSnapshotAllIndicesWithAdditionalParametersErr(t *testing.T) { +func TestSnapshotAllIndicesWithAdditionalParametersNilValue(t *testing.T) { testSetup := &ServerSetup{ Method: "PUT", Path: "/_snapshot/backup-repo/snapshot1", - Body: `{"metadata":{"taken_because":"backup before upgrading","taken_by":"user123"}}`, Response: `{"acknowledged": true }`, } @@ -1444,8 +1443,8 @@ func TestSnapshotAllIndicesWithAdditionalParametersErr(t *testing.T) { err := client.SnapshotAllIndicesWithBodyParams("backup-repo", "snapshot1", nil) - if err == nil { - t.Fatalf("should have thrown an error") + if err != nil { + t.Fatalf("Should be able to take Nil body params: %s", err) } }