From 7d5e3b4d5333f2d124e4ccd023a88126c9084312 Mon Sep 17 00:00:00 2001 From: Max Horstmann Date: Thu, 20 Jun 2013 15:33:24 -0400 Subject: [PATCH] Add error handling to GetIndicesPointingToAlias. /wrongname/_aliases used to return an empty array (e.g. in ES 0.20) for a non-existing alias, but in more recent ES versions (0.90) it returns {"error":"IndexMissingException[[wrongname] missing]","status":404} So we need to add explicit error handling here, otherwise GetIndicesPointingToAlias returns two "indices" called "error" and "status". --- src/Nest/ElasticClient-Aliases.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Nest/ElasticClient-Aliases.cs b/src/Nest/ElasticClient-Aliases.cs index 91ed3b046e8..c0dae0e76d1 100644 --- a/src/Nest/ElasticClient-Aliases.cs +++ b/src/Nest/ElasticClient-Aliases.cs @@ -30,18 +30,22 @@ private string _createCommand(string command, AliasParams aliasParam) return cmd; } - /// - /// Get all the indices pointing to an alias - /// - public IEnumerable GetIndicesPointingToAlias(string alias) - { - var path = this.PathResolver.CreateIndexPath(alias, "/_aliases"); - var status = this.Connection.GetSync(path); - var r = this.Deserialize>(status.Result); - return r == null ? Enumerable.Empty() : r.Keys; - } + /// + /// Get all the indices pointing to an alias + /// + public IEnumerable GetIndicesPointingToAlias(string alias) + { + var path = this.PathResolver.CreateIndexPath(alias, "/_aliases"); + var status = this.Connection.GetSync(path); + if (!status.Success) + { + return Enumerable.Empty(); + } + var r = this.Deserialize>(status.Result); + return r == null ? Enumerable.Empty() : r.Keys; + } - /// + /// /// Repoint an alias from a set of old indices to a set of new indices in one operation /// public IIndicesOperationResponse Swap(string alias, IEnumerable oldIndices, IEnumerable newIndices)