예제 #1
0
        public void CreateAlias(string index, string alias)
        {
            var createResp = defaultClient.Alias(desc => desc
                                                 .Add(aad => aad
                                                      .Index(index)
                                                      .Alias(alias)));

            ResponseValidator(createResp);
        }
예제 #2
0
        private void updateAlias(string alias, string index, bool close = true)
        {
            Console.WriteLine($"Updating `{alias}` alias to `{index}`...");

            var aliasDescriptor = new BulkAliasDescriptor();
            var oldIndices      = elasticClient.GetIndicesPointingToAlias(alias);

            foreach (var oldIndex in oldIndices)
            {
                aliasDescriptor.Remove(d => d.Alias(alias).Index(oldIndex));
            }

            aliasDescriptor.Add(d => d.Alias(alias).Index(index));

            Console.WriteLine(elasticClient.Alias(aliasDescriptor));

            // cleanup
            if (!close)
            {
                return;
            }
            foreach (var toClose in oldIndices.Where(x => x != index))
            {
                Console.WriteLine($"Closing {toClose}");
                elasticClient.CloseIndex(toClose);
            }
        }
예제 #3
0
 public void SwapAlias(string oldIndex, string newIndex)
 {
     if (!string.IsNullOrEmpty(oldIndex))
     {
         client.Alias(alias =>
         {
             alias.Add(c => c.Index(newIndex).Alias(this.aliasName));
             if (client.IndexExists(oldIndex).Exists)
             {
                 alias.Remove(c => c.Index(oldIndex).Alias(aliasName));
             }
             return(alias);
         });
     }
     else
     {
         client.Alias(a => a.Add(c => c.Index(newIndex).Alias(aliasName)));
     }
 }
예제 #4
0
        public static void createDateBasedAliases(ElasticClient esClient, string indexName)
        {
            Utils.Log("Creating aliases for index {0}-*...", indexName);

            //create the alias
            esClient.Alias(a => a
                           .Add(add => add
                                .Index(indexName + "-*")
                                .Alias(indexName)
                                )
                           );
        }
예제 #5
0
        private static List <Func <object> > IndexCommands(ElasticClient elastic)
        {
            return(new List <Func <object> >
            {
                () => elastic.CreateIndex("test_index_1"),
                () => elastic.IndexExists("test_index_1"),
                () => elastic.UpdateIndexSettings(new UpdateIndexSettingsRequest("test_index_1")
                {
                    IndexSettings = new IndexSettings()
                    {
                        Sorting = new SortingSettings
                        {
                            Fields = new Field("Title"),
                        },
                    },
                }),
                () => elastic.Alias(new BulkAliasRequest
                {
                    Actions = new List <IAliasAction>
                    {
                        new AliasAddAction
                        {
                            Add = new AliasAddOperation
                            {
                                Index = "test_index_1",
                                Alias = "test_index_2",
                            },
                        },
                    },
                }),
                () => elastic.GetAliasesPointingToIndex("test_index_1"),
                () => elastic.PutAlias("test_index_1", "test_index_3"),
                () => elastic.AliasExists(new AliasExistsRequest("test_index_1")),
                () => elastic.DeleteAlias(new DeleteAliasRequest("test_index_1", "test_index_3")),
                () => elastic.DeleteAlias(new DeleteAliasRequest("test_index_1", "test_index_2")),
                () => elastic.CreateIndex("test_index_4"),
#if (ELASTICSEARCH_6_1 && !DEFAULT_SAMPLES)
                () => elastic.SplitIndex("test_index_1", "test_index_4"),
#endif
                () => elastic.DeleteIndex("test_index_4"),
                () => elastic.CloseIndex("test_index_1"),
                () => elastic.OpenIndex("test_index_1"),
                () => elastic.PutIndexTemplate(new PutIndexTemplateRequest("test_template_1")),
                () => elastic.IndexTemplateExists("test_template_1"),
                () => elastic.DeleteIndexTemplate("test_template_1"),
                () => elastic.IndicesShardStores(),
                () => elastic.IndicesStats("test_index_1"),
                () => elastic.DeleteIndex("test_index_1"),
                () => elastic.GetAlias(new GetAliasRequest()),
            });
        }
예제 #6
0
 private static List <Func <object> > IndexCommands(ElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.CreateIndex("test_index_1"),
         () => elastic.IndexExists("test_index_1"),
         () => elastic.UpdateIndexSettings(new UpdateIndexSettingsRequest("test_index_1")
         {
             IndexSettings = new IndexSettings()
             {
                 // V6 feature
                 // Sorting = new SortingSettings
                 // {
                 //     Fields = new Field("Title"),
                 // },
             },
         }),
         () => elastic.Alias(new BulkAliasRequest
         {
             Actions = new List <IAliasAction>
             {
                 new AliasAddAction
                 {
                     Add = new AliasAddOperation
                     {
                         Index = "test_index_1",
                         Alias = "test_index_2",
                     },
                 },
             },
         }),
         () => elastic.GetAliasesPointingToIndex("test_index_1"),
         () => elastic.PutAlias("test_index_1", "test_index_3"),
         // () => elastic.AliasExists(new AliasExistsRequest("test_index_1")), // TODO: enable
         () => elastic.DeleteAlias(new DeleteAliasRequest("test_index_1", "test_index_3")),
         () => elastic.DeleteAlias(new DeleteAliasRequest("test_index_1", "test_index_2")),
         () => elastic.CreateIndex("test_index_4"),
         // () => elastic.SplitIndex("test_index_1", "test_index_4"), // V6 Feature
         () => elastic.DeleteIndex("test_index_4"),
         () => elastic.CloseIndex("test_index_1"),
         () => elastic.OpenIndex("test_index_1"),
         () => elastic.PutIndexTemplate(new PutIndexTemplateRequest("test_template_1")),
         () => elastic.IndexTemplateExists("test_template_1"),
         () => elastic.DeleteIndexTemplate("test_template_1"),
         () => elastic.IndicesShardStores(),
         () => elastic.IndicesStats("test_index_1"),
         () => elastic.DeleteIndex("test_index_1"),
         () => elastic.GetAlias(new GetAliasRequest()),
     });
 }
예제 #7
0
        public static void SwapAlias()
        {
            var indexExists = Client.IndexExists(ElasticSearchConfiguration.LiveIndexAlias).Exists;

            Client.Alias(aliases =>
            {
                if (indexExists)
                {
                    aliases.Add(a => a.Alias(ElasticSearchConfiguration.OldIndexAlias).Index(ElasticSearchConfiguration.LiveIndexAlias));
                }

                return(aliases
                       .Remove(a => a.Alias(ElasticSearchConfiguration.LiveIndexAlias).Index("*"))
                       .Add(a => a.Alias(ElasticSearchConfiguration.LiveIndexAlias).Index(ElasticSearchConfiguration.IndexName)));
            });

            var oldIndices = Client.GetIndicesPointingToAlias(ElasticSearchConfiguration.OldIndexAlias);

            foreach (var oldIndex in oldIndices)
            {
                Client.DeleteIndex(oldIndex);
            }
        }
예제 #8
0
 private static List <Func <object> > IndexCommands(ElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.CreateIndex("test_index_1"),
         () => elastic.IndexExists("test_index_1"),
         () => elastic.UpdateIndexSettings(new UpdateIndexSettingsRequest("test_index_1")
         {
             IndexSettings = new IndexSettings()
             {
                 // V6 feature
                 // Sorting = new SortingSettings
                 // {
                 //     Fields = new Field("Title"),
                 // },
             },
         }),
         () => elastic.Alias(new BulkAliasRequest
         {
             Actions = new List <IAliasAction>
             {
                 new AliasAddAction
                 {
                     Add = new AliasAddOperation
                     {
                         Index = "test_index_1",
                         Alias = "test_index_2",
                     },
                 },
             },
         }),
         () => elastic.GetAliasesPointingToIndex("test_index_1"),
         () => elastic.PutAlias("test_index_1", "test_index_3"),
         // () => elastic.AliasExists(new AliasExistsRequest("test_index_1")), // TODO: enable
         () => elastic.DeleteAlias(new DeleteAliasRequest("test_index_1", "test_index_3")),
         () => elastic.DeleteAlias(new DeleteAliasRequest("test_index_1", "test_index_2")),
         () => elastic.CreateIndex("test_index_4"),
         // () => elastic.SplitIndex("test_index_1", "test_index_4"), // V6 Feature
         () => elastic.DeleteIndex("test_index_4"),
         () => elastic.CloseIndex("test_index_1"),
         () => elastic.OpenIndex("test_index_1"),
         () => elastic.PutIndexTemplate(new PutIndexTemplateRequest("test_template_1")),
         () => elastic.IndexTemplateExists("test_template_1"),
         () => elastic.DeleteIndexTemplate("test_template_1"),
         () => elastic.IndicesShardStores(),
         () => elastic.IndicesStats("test_index_1"),
         () => elastic.DeleteIndex("test_index_1"),
         () => elastic.GetAlias(new GetAliasRequest()),
         () => elastic.ReindexOnServer(new ReindexOnServerRequest
         {
             Source = new ReindexSource
             {
                 Remote = new RemoteSource
                 {
                     Host = new Uri("http://" + Host()),
                     Username = "******",
                     Password = "******"
                 },
                 Index = "some_index",
                 Size = 10
             },
             Destination = new ReindexDestination
             {
                 Index = "some_index_clone",
             }
         })
     });
 }
예제 #9
0
        public bool DeleteAlias(CatAliasesRecord alias)
        {
            IBulkAliasResponse aliasResponse = client.Alias(a => a.Remove(r => r.Index(alias.Index).Alias(alias.Alias)));

            return(aliasResponse.Acknowledged);
        }
예제 #10
0
 /// <summary>
 /// Remove an alias associated with an index.
 /// </summary>
 /// <param name="index">The name of the index.</param>
 /// <param name="alias">The name of the alias to remove.</param>
 public void RemoveAlias(string index, string indexAlias, string groupAlias)
 {
     _elasticClient.Alias(s => s.Remove(a => a.Index(index).Alias(indexAlias)));
     _elasticClient.Alias(s => s.Remove(a => a.Index(index).Alias(groupAlias)));
 }