Exemplo n.º 1
0
        public OkObjectResult CreateIndex(string indexName = "wizplant")
        {
            var client = ElasticSearchHelper.GetElasticClient(_connStrings.Value.ESWizplantUrl);
            var bol    = ElasticSearchHelper.CreateIndex <ElasticModel>(client, indexName);

            return(Ok(new { name = "创建索引", IsSuccess = bol }));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            #region 发布订阅
            //var channel = "FYQ" + "logs_publish_channel";
            //RedisHelp.SubServer.Subscribe(channel, new Action<RedisChannel, RedisValue>((chan, message) =>
            //{
            //    Console.WriteLine(chan + "订阅到的消息是:" + message);
            //}));
            #endregion
            var logDirectionPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log");
            var path             = Path.Combine(logDirectionPath, string.Format("log{0}.txt", DateTime.Now.ToString("yyyyMMdd")));
            var errpath          = Path.Combine(logDirectionPath, string.Format("errlog{0}.txt", DateTime.Now.ToString("yyyyMMdd")));
            if (!Directory.Exists(logDirectionPath))
            {
                Directory.CreateDirectory(logDirectionPath);
            }
            if (!File.Exists(path))
            {
                File.CreateText(path);
            }
            if (!File.Exists(errpath))
            {
                File.CreateText(errpath);
            }
            int i = 0;

            while (true)
            {
                Console.WriteLine("数据查询中...testcore111....{0}", i);
                var str = string.Empty;
                i++;
                try
                {
                    var loginfo = RedisHelper.ListRightPop <LogInfoDto>(out str);
                    if (loginfo != null)
                    {
                        ElasticSearchHelper.InSertElastic(loginfo);
                        if (ConfigHelper.AppName == "FYQ")
                        {
                            // WriteInfoToFile(str, path);
                        }
                    }
                    else
                    {
                        Thread.Sleep(3000);
                    }
                }
                catch (Exception ex)
                {
                    Thread.Sleep(3000);
                    WriteInfoToFile("ErrorLog_" + DateTime.Now.ToString() + ex.Message, errpath);
                }
                Thread.Sleep(10);
            }
        }
Exemplo n.º 3
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Utils.WriteLogFile("启动服务...");
                string   time        = ConfigurationManager.AppSettings["time"].ToString();
                DateTime lastruntime = DateTime.Parse("1900-01-01");
                timer = new Timer((o) =>
                {
                    if (DateTime.Now - lastruntime > TimeSpan.FromMinutes(int.Parse(time)))
                    {
                        lastruntime = DateTime.Now;
                        try
                        {
                            Utils.WriteLogFile("正在导入数据...");
                            string rs = ElasticSearchHelper.SetIndexAlias();
                            if (rs.Length > 0)
                            {
                                Utils.WriteLogFile("Mall导入完成,新的索引名称为:" + rs);
                            }
                            else
                            {
                                Utils.WriteLogFile("Mall导入失败");
                            }

                            rs = ElasticSearchHelper.SetSuggestIndex();
                            if (rs.Length > 0)
                            {
                                Utils.WriteLogFile("MallSuggest导入完成,新的索引名称为:" + rs);
                            }
                            else
                            {
                                Utils.WriteLogFile("MallSuggest导入失败");
                            }
                        }
                        catch (Exception ex)
                        {
                            Utils.WriteLogFile(ex.Message);
                        }
                    }
                }, null, 0, 1000);
                Utils.WriteLogFile("服务已启动");
            }
            catch (Exception ex1)
            {
                Utils.WriteLogFile(ex1.Message);
            }
        }
        public async Task GetTestElasticSearchConnectionResult()
        {
            try
            {
                string         url = GetQueryStringValueAndAssertIfSingleAndNotEmpty("url");
                string         authenticationJson = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
                Authentication authentication     = JsonConvert.DeserializeObject <Authentication>(authenticationJson);

                ElasticClient client = ElasticSearchHelper.CreateClient(new ElasticSearchConnectionString {
                    Nodes = new[] { url }, Authentication = authentication
                });

                PingResponse pingResult = await client.PingAsync();

                if (pingResult.IsValid)
                {
                    DynamicJsonValue result = new() { [nameof(NodeConnectionTestResult.Success)] = true, [nameof(NodeConnectionTestResult.TcpServerUrl)] = url, };
Exemplo n.º 5
0
        protected virtual string[] VerifiedNodesValueFactory()
        {
            var singleLocalNode = new[] { "http://localhost:9200" };

            if (TryConnect(singleLocalNode, out var pingResponse))
            {
                return(singleLocalNode);
            }

            if (Nodes.Value.Length == 0)
            {
                throw new InvalidOperationException($"Environment variable {EnvironmentVariable} is empty");
            }


            if (TryConnect(Nodes.Value, out pingResponse))
            {
                return(Nodes.Value);
            }

            throw new InvalidOperationException($"Can't ping Elastic Search instance. Provided urls: {string.Join(',', Nodes.Value)}", pingResponse?.OriginalException);


            bool TryConnect(string[] nodes, out PingResponse response)
            {
                try
                {
                    var client = ElasticSearchHelper.CreateClient(new ElasticSearchConnectionString {
                        Nodes = nodes
                    }, requestTimeout: TimeSpan.FromSeconds(1), pingTimeout: TimeSpan.FromSeconds(1));

                    response = client.Ping();

                    return(response.IsValid);
                }
                catch
                {
                    response = null;

                    return(false);
                }
            }
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            try
            {
                string IndexNew = string.Format("{0:yyyyMMddHHmmss}", DateTime.Now);
                Console.WriteLine("正在导入数据...");
                string rs = ElasticSearchHelper.SetIndexAlias();
                if (rs.Length > 0)
                {
                    Utils.WriteLogFile("Mall导入完成,新的索引名称为:" + rs);
                    Console.WriteLine("Mall导入完成,新的索引名称为:" + rs);
                }
                else
                {
                    Utils.WriteLogFile("Mall导入失败");
                    Console.WriteLine("Mall导入失败");
                }

                rs = ElasticSearchHelper.SetSuggestIndex();
                if (rs.Length > 0)
                {
                    Utils.WriteLogFile("MallSuggest导入完成,新的索引名称为:" + rs);
                    Console.WriteLine("MallSuggest导入完成,新的索引名称为:" + rs);
                }
                else
                {
                    Utils.WriteLogFile("MallSuggest导入失败");
                    Console.WriteLine("MallSuggest导入失败");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            int count = 100;

            for (int i = 0; i < count; i++)
            {
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine((count - i) + "秒后自动关闭");
            }
        }
Exemplo n.º 7
0
        public List <test> GetJackietestModel()
        {
            var result = ElasticSearchHelper.SearchEntityBySql <test>("select id,date,name,twitter from test limit 10");

            return(result);
        }
Exemplo n.º 8
0
 public Function()
 {
     _client = ElasticSearchHelper.GetInstance(ConfigurationHelper.Instance);
 }
 public PeopleController()
 {
   searchHelper = new ElasticSearchHelper();
 }