コード例 #1
0
        /// <summary>
        /// Delete index
        /// </summary>
        public virtual void DeleteIndex(string alias = null)
        {
            lock (_lockObject)
            {
                var client = CreateElasticClient(CommonConnectionSettings.ConnectionSettings); // use a raw elasticclient because we just need this to be quick

                var indicesToDelete = new List <string>();

                if (alias == null) // determine if we are deleting only aliases of all index prefixes
                {
                    var indexPrefix = $"{Index}_";
                    var indices     = client.CatIndices();

                    if (indices?.Records?.Any() == true)
                    {
                        foreach (var index in indices.Records.Where(i => i.Index.StartsWith(indexPrefix)).Select(i => i.Index))
                        {
                            indicesToDelete.Add(index);
                        }
                    }
                }
                else
                {
                    var aliasPrefix = $"{Index}-" + alias;

                    var aliases = client.CatAliases();

                    if (aliases?.Records?.Any() == true)
                    {
                        foreach (var index in aliases.Records.Where(a => a.Alias.StartsWith(aliasPrefix)).Select(i => i.Index))
                        {
                            indicesToDelete.Add(index);
                        }
                    }
                }

                var deleted = new List <string>();

                if (indicesToDelete.Any())
                {
                    foreach (var index in indicesToDelete)
                    {
                        var response = client.DeleteIndex(index);

                        if (!response.IsValid)
                        {
                            Logger.Error($"Could not run a delete index: {response.DebugInformation}");
                        }
                        else
                        {
                            deleted.Add(index);
                        }
                    }

                    DeletedIndices?.Invoke(deleted);
                }

                Clients?.Clear(); // need to force a re-creation
            }
        }
コード例 #2
0
        /// <summary>
        /// Delete index
        /// </summary>
        public virtual void DeleteIndex()
        {
            lock (lockObject)
            {
                var client  = CreateElasticClient(CommonConnectionSettings.Service.ConnectionSettings); // use a raw elasticclient because we just need this to be quick
                var indices = client.CatIndices();

                if (indices != null && indices.Records != null && indices.Records.Any())
                {
                    var indicesToDelete = new List <string>();

                    foreach (var index in indices.Records.Where(i => i.Index.StartsWith(Index + "_")).Select(i => i.Index))
                    {
                        var response = client.DeleteIndex(index);

                        if (!response.IsValid)
                        {
                            Logger.Error("Could not run a delete index: " + response.DebugInformation);
                        }
                        else
                        {
                            indicesToDelete.Add(index);
                        }
                    }

                    DeletedIndices?.Invoke(indicesToDelete);
                }

                // todo: this is a temp fix to keep multiple templates from getting added, shouldn't exist long term....
                if (client.IndexTemplateExists("analyzer_disabling").Exists)
                {
                    // clean up template that was too generic in a shared environment
                    client.DeleteIndexTemplate("analyzer_disabling");
                }

                clients = new Dictionary <CultureInfo, IVulcanClient>(); // need to force a re-creation
            }
        }