From 604c6382452bb7aeed4993ba1f657eb896bef4ee Mon Sep 17 00:00:00 2001 From: William Griffiths Date: Wed, 2 Mar 2016 16:00:04 +0000 Subject: [PATCH 1/2] Add function to remove alias --- lib/indicesaliasdelete.go | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/indicesaliasdelete.go diff --git a/lib/indicesaliasdelete.go b/lib/indicesaliasdelete.go new file mode 100644 index 00000000..862e5a08 --- /dev/null +++ b/lib/indicesaliasdelete.go @@ -0,0 +1,61 @@ +// Copyright 2013 Matthew Baird +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http:www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package elastigo + +import ( + "encoding/json" + "fmt" +) + +type JsonRemoveAliases struct { + Actions []JsonAliasRemove `json:"actions"` +} + +type JsonAliasRemove struct { + Remove JsonAlias `json:"remove"` +} + + +// The API allows you to remove an index alias through an API. +func (c *Conn) RemoveAlias(index string, alias string) (BaseResponse, error) { + var url string + var retval BaseResponse + + if len(index) > 0 { + url = "/_aliases" + } else { + return retval, fmt.Errorf("You must specify an index to create the alias on") + } + + jsonAliases := JsonRemoveAliases{} + jsonAliasRemove := JsonAliasRemove{} + jsonAliasRemove.Remove.Alias = alias + jsonAliasRemove.Remove.Index = index + jsonAliases.Actions = append(jsonAliases.Actions, jsonAliasRemove) + requestBody, err := json.Marshal(jsonAliases) + + if err != nil { + return retval, err + } + + body, err := c.DoCommand("POST", url, nil, requestBody) + if err != nil { + return retval, err + } + + jsonErr := json.Unmarshal(body, &retval) + if jsonErr != nil { + return retval, jsonErr + } + + return retval, err +} From 1875fc477d357187d39e50ea1bde334835cc283e Mon Sep 17 00:00:00 2001 From: William Griffiths Date: Wed, 2 Mar 2016 16:26:07 +0000 Subject: [PATCH 2/2] rename file to match method name --- lib/{indicesaliasdelete.go => indicesremovealias.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{indicesaliasdelete.go => indicesremovealias.go} (100%) diff --git a/lib/indicesaliasdelete.go b/lib/indicesremovealias.go similarity index 100% rename from lib/indicesaliasdelete.go rename to lib/indicesremovealias.go