private async Task <CacheItem> GetCacheItemFromDatabaseAsync(string key)
        {
            var connectionSettings = new Nest.ConnectionSettings(new Uri(_uri)).DefaultMappingFor <CacheItem>(m => m.IndexName(_indexName));
            var client             = new Nest.ElasticClient(connectionSettings);
            var response           = await client.GetAsync <CacheItem>(new Nest.DocumentPath <CacheItem>(key));

            return(response.Source);
        }
Example #2
0
 public void NestPing_should_work()
 {
     var httpConnection = new AwsHttpConnection(TestConfig.AwsSettings);
     var pool = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
     var config = new Nest.ConnectionSettings(pool, httpConnection);
     var client = new Nest.ElasticClient(config);
     var response = client.Ping();
     Assert.AreEqual(true, response.IsValid);
 }
Example #3
0
        public void NestPing_should_work()
        {
            var httpConnection = new AwsHttpConnection(Region, Credentials);
            var pool           = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
            var config         = new Nest.ConnectionSettings(pool, httpConnection);
            var client         = new Nest.ElasticClient(config);
            var response       = client.Ping();

            Assert.AreEqual(true, response.IsValid);
        }
Example #4
0
        private void CreateElasticClient(List <Uri> uris)
        {
            var connectionPool = new SniffingConnectionPool(uris);

            var connectionSettings = new Nest.ConnectionSettings(connectionPool)
                                     .SniffOnStartup()
                                     .SniffOnConnectionFault()
                                     .DisableAutomaticProxyDetection()
                                     .ThrowExceptions();

            _elasticClient = new Nest.ElasticClient(connectionSettings);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var kafkaConfiguration = Configuration.GetSection(nameof(ElasticSearchConfiguration))
                                     .Get <ElasticSearchConfiguration>();
            var settings = new Nest.ConnectionSettings(new Uri(kafkaConfiguration.Url))
                           .DefaultIndex(kafkaConfiguration.DefaultIndex);

            var esClient = services.ElasticSearchDependencyRegister(settings);

            esClient.Indices.Create("testindex", c => c.Map <Model.TestModel>(m => m.AutoMap()));


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Example #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IVideoService, VideoService>();
            services.AddSingleton <IRedisService, RedisService>();
            services.AddSingleton <IMagnetSearchService, MagnetSearchService>();
            services.AddSingleton <IVideoRankingService, VideoRankingService>();

            services.AddResponseCompression();

            services.AddMemoryCache();
            services.AddSession();

            services.AddMvc(options =>
            {
                options.Filters.Add <GlobalExceptionFilter>();
            });

            services.AddOptions();

            #region Redis
            var RedisClient = new CSRedisClient(Configuration["Redis:CSRedisConnection"]);
            services.AddSingleton(_ => RedisClient);
            #endregion

            #region MongoDB
            var MongoConnectionString = Configuration["MongoDB:connectionString"];
            var mClient = new MongoClient(MongoConnectionString);
            services.AddSingleton(_ => mClient);
            #endregion

            #region ElasticSearch
            var EsUrls  = Configuration["ElasticSearch:Url"].Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
            var EsNodes = new List <Uri>();
            EsUrls.ForEach(url =>
            {
                EsNodes.Add(new Uri(url));
            });
            var EsPool     = new Elasticsearch.Net.StaticConnectionPool(EsNodes);
            var EsSettings = new Nest.ConnectionSettings(EsPool);
            var EsClient   = new Nest.ElasticClient(EsSettings);
            services.AddSingleton(_ => EsClient);
            #endregion
        }
Example #7
0
        public void ConfigureServices(IServiceCollection services)
        {
            // MVC
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // Dependency Injection
            Game.Ranking.Model.Startup.ConfigureServices(services);
            Game.Ranking.Infrastructure.Replication.Startup.ConfigureServices(services);
            Game.Ranking.Infrastructure.InMemory.Startup.ConfigureServices(services);
            Game.Ranking.Services.Startup.ConfigureServices(services);

            // ElasticSearch connection configuration
            services.AddSingleton <ElasticClientConfigurator>(provider =>
            {
                var settings = new Nest.ConnectionSettings(new Uri(Configuration.GetConnectionString("ElasticSearch")));
                settings.DisableDirectStreaming();
                return(new ElasticClientConfigurator(settings));
            });

            // Initialize AutoMapper
            Mapper.Initialize(cfg =>
            {
                Game.Ranking.Services.Startup.AddMapperProfiles(cfg);
            });

            // Add Swagger
            services.AddSwaggerGen(cfg =>
            {
                cfg.SwaggerDoc("v1", new Info {
                    Title = "Game.Ranking.API", Version = "v1"
                });

                foreach (var xml in Directory.EnumerateFiles(AppContext.BaseDirectory, "Game.Ranking.*.xml"))
                {
                    cfg.IncludeXmlComments(xml, true);
                }
            });

            // Add Hangfire (Job scheduler)
            services.AddHangfire(config => config.UseStorage(new MemoryStorage()));
        }
Example #8
0
        static public List<string> getMessages(long channelIDs)
        {
            List<string> messages = new List<string>();
            Uri Server_ = new Uri("http://192.168.30.106:8200/");
            var pool_DataReader = new Elasticsearch.Net.SingleNodeConnectionPool(Server_);
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

            int month = DateTime.Now.Month;
            int previousMonth = DateTime.Now.AddMonths(-1).Month;
            string index = $"telegramcrw-{DateTime.Now.Year}-{month.ToString("##")}";

            Nest.ConnectionSettings connectionSettings_DataReader =                
                new Nest.ConnectionSettings(pool_DataReader).DefaultIndex(index);
            var client_DataReader = new Nest.ElasticClient(connectionSettings_DataReader);

            string minDate = DateTime.Now.AddDays(-10).ToString("yyyy-MM-dd HH:mm:ss" + ".000");
            var result = client_DataReader.Search<telegramcrw_message>(s => s
            .Type("message")
            .MatchAll()
            //.From(0)
            .Size(100)
            .Query(q => q
                .DateRange(r => r
                    .Field(f => f.createDate)
                    .GreaterThanOrEquals(minDate)
                //.LessThan("2018-12-20 19:05:00.000")
                )
                // Added without any debug
                && q.Term("language", "102097")
                && q.Term("fK_ChannelId", channelIDs)
            )
            //.Scroll("5m")
            //.SearchType(Elasticsearch.Net.SearchType.QueryThenFetch)
            .Sort(w => w.Ascending(f => f.createDate))
            );
            for (int j = 0; j < result.Documents.Count; j++)
                messages.Add(result.Documents.ElementAt(j).messageTextCleaned);

            return messages;
        }
Example #9
0
        private void Recreate(params object[] parameters)
        {
            JobHandle = Context.Job.Handle;

            if (parameters.Length != 1)
            {
                return;
            }

            var item = parameters[0] as Item;

            if (item == null)
            {
                return;
            }

            var job = JobManager.GetJob(JobHandle);

            // Connecting to Elasticsearch
            string protocol = Settings.GetSetting("ElasticSearch.Protocol", "http");
            string host     = Settings.GetSetting("ElasticSearch.Host", "elastic.local");
            string port     = Settings.GetSetting("ElasticSearch.Port", "9200");

            var node     = new Uri(string.Format("{0}://{1}:{2}", protocol, host, port));
            var settings = new Nest.ConnectionSettings(node);
            var client   = new Nest.ElasticClient(settings);

            // Re-creating index
            var indexName = Settings.GetSetting("ElasticSearch.ArticlesIndex", "articles-index");

            DisplayStatusMessage(job, string.Format("Deleting '{0}' index", indexName));
            var deleteResponse = client.DeleteIndex(indexName);

            DisplayStatusMessage(job, string.Format("The index {0} - has been deleted? - {1}", indexName, deleteResponse.Acknowledged));

            DisplayStatusMessage(job, string.Format("Creating '{0}' index", indexName));
            var createResponse = client.CreateIndex(indexName);

            DisplayStatusMessage(job, string.Format("The index {0} - has been created? {1}", indexName, createResponse.Acknowledged));
        }