Exemplo n.º 1
0
        public static IEnumerable <CatIndicesRecord> GetOutOfDateIndices(IElasticClient client, IndexEntry indexEntry, ILogger log)
        {
            var indices = new List <CatIndicesRecord>();

            var indexPattern = GetIndexPattern(indexEntry.Prefix);

            var catIndicesResponse = client.CatIndices(x => x.Index(indexPattern));

            if (catIndicesResponse.IsValid)
            {
                foreach (var idx in catIndicesResponse.Records)
                {
                    var idxDate     = idx.Index.Substring(indexPattern.Length - 1);
                    var idxDateTime = DateTime.Parse(idxDate, new CultureInfo("en-US"));

                    if (idxDateTime.AddDays(indexEntry.RetentionDays) < DateTime.Today)
                    {
                        indices.Add(idx);
                    }
                }
            }
            else
            {
                log.LogWarning(catIndicesResponse.DebugInformation);
            }

            return(indexEntry.DeleteCloseIndicesOnly
                ? indices.Where(i => i.Index.ToUpperInvariant() == "CLOSE")
                : indices);
        }
        private IList <string> GetIndexList(IElasticClient client)
        {
            var result = client.CatIndices(
                d => d.RequestConfiguration(r =>
                                            r.RequestTimeout(5 * 60 * 1000)));

            return(result.Records.Select(i => i.Index).ToList());
        }