public static void AddIndexDataFromIndex(string baseUrl, string indexName, string entity, string descriptionsIndexUrl, string relationshipsIndexUrl, string conceptId, AllowableValuesEnum allowedValues) { string indexUrl = baseUrl + "/" + indexName + "/" + entity; var parentIds = new List<string>(); var childrenIds = new List<string>(); int total = 0; int count = 1; int level = 1; Console.WriteLine("Starting index data processing: " + level.ToString()); Stopwatch mainWatch = new Stopwatch(); mainWatch.Start(); if (allowedValues == AllowableValuesEnum.ThisCodeAndDescendants || allowedValues == AllowableValuesEnum.ThisCodeOnly) { var descriptions = ElasticSearchUtility.GetDescriptions(descriptionsIndexUrl, conceptId); foreach (var description in descriptions) { ElasticSearchUtility.WriteToIndex(indexUrl, conceptId, description.Term, total, description.TypeId); total++; } } if (allowedValues != AllowableValuesEnum.ThisCodeOnly) { parentIds.Add(conceptId); while (parentIds.Count > 0) { Stopwatch levelWatch = new Stopwatch(); levelWatch.Start(); Console.WriteLine(string.Format("\n\nStarted level {0}", level)); count = 1; childrenIds = ElasticSearchUtility.GetChildren(indexUrl, relationshipsIndexUrl, parentIds.ToArray()); foreach (var child in childrenIds) { var descriptions = ElasticSearchUtility.GetDescriptions(descriptionsIndexUrl, child); foreach (var description in descriptions) { ElasticSearchUtility.WriteToIndex(indexUrl, child, description.Term, total, description.TypeId); total++; count++; } } string[] ids = new string[childrenIds.Count]; childrenIds.CopyTo(ids, 0); parentIds.Clear(); parentIds = ids.ToList(); //Console.WriteLine(string.Format("Children retrieved: {0}", retrieved)); Console.WriteLine(string.Format("Children added: {0}", count)); //Console.WriteLine(string.Format("Children with duplicates: {0}", duplicates)); Console.WriteLine(string.Format("Total children added so far: {0}", total)); Console.WriteLine(string.Format("Level process complete: {0}| In {1}:{2}:{3}.", level, levelWatch.Elapsed.Hours, levelWatch.Elapsed.Minutes, levelWatch.Elapsed.Seconds)); level++; } } mainWatch.Stop(); Console.WriteLine(string.Format("Total data added: {0}", total)); Console.WriteLine(string.Format("Completed: {0}:{1}:{2}", mainWatch.Elapsed.Hours, mainWatch.Elapsed.Minutes, mainWatch.Elapsed.Seconds)); Console.WriteLine("\n"); //Console.ReadLine(); }
public static void BuildIndexFromIndex(string indexName, string entity, string baseUrl, string descriptionIndexUrl, string relationshipsIndexUrl, string[] conceptIds, AllowableValuesEnum allowedValues) { Stopwatch indexWatch = new Stopwatch(); indexWatch.Start(); // add data Console.WriteLine(string.Format("Will now add data to index \"{0}\"", indexName)); foreach (var conceptId in conceptIds) { AddIndexDataFromIndex(baseUrl, indexName, entity, descriptionIndexUrl, relationshipsIndexUrl, conceptId, allowedValues); } indexWatch.Stop(); Console.WriteLine(string.Format("Finished building index \"{0}\"", indexName)); Console.WriteLine(string.Format("Index build time: {0}:{1}:{2}", indexWatch.Elapsed.Hours, indexWatch.Elapsed.Minutes, indexWatch.Elapsed.Seconds)); }