/// <summary> /// 索引处理 /// </summary> /// <param name="type">索引类型</param> /// <param name="log"></param> public DataInit(string type, ILog log) { _log = log; _indexType = type; _indexConfig = IndexConfigHelper.IndexConfig(type); if (_indexConfig == null) { throw new Exception(string.Format("{0}:未找到对应索引类型的配置信息!", _indexType)); } _log.Info(string.Format("{0}:开始操作索引...", type)); tempIndexName = _indexConfig.IndexName + DateTime.Now.ToString("yyyyMMddHHmmss"); //es操作对象 _es = new EsHandle(tempIndexName, _log); //创建一个索引 _es.CreateIndex(_indexConfig.Replicas, _indexConfig.Shards); try { _log.Info(string.Format("{0}:索引操作完成...", type)); //索引器容器 _indexerContainer = new IndexerContainer(_log); _log.Info(string.Format("{0}:开始索引数据...", type)); } catch { //有异常删除已创建的索引 _es.DeleteIndex(tempIndexName); throw; } }
static void Main(string[] args) { string cmd = string.Empty; if (args.Length > 0) { cmd = args[0]; } while (true) { string indexType; #region input while (true) { if (string.IsNullOrEmpty(cmd)) { CmdTips(); Log.Info("输入索引类型!"); cmd = Console.ReadLine(); if (IndexConfigHelper.Any(cmd)) { indexType = cmd; break; } cmd = string.Empty; continue; } if (IndexConfigHelper.Any(cmd)) { indexType = cmd; break; } } #endregion Log.Info("============================================\n"); Log.InfoFormat("开始处理:{0}...", indexType); try { //创建索引处理对象 var indexHandle = new DataInit(indexType, Log); //执行处理 indexHandle.Exec(); } catch (Exception ex) { Console.WriteLine(ex.Message); } cmd = string.Empty; Log.Info("============================================\n"); } }