private static void ImportNocPostitle(ConnectionString connectionString, string fileName)
        {
            var client = new ElasticSearchClient <NocPostitle>(connectionString, "indexb");

            // Creates the Index, if neccessary:
            client.CreateIndex();

            // Bulk Insert Data:
            foreach (var batch in GetNocPostitle(fileName).Batch(100))
            {
                var response = client.BulkInsert(batch);
            }
        }
        public static void Main(string[] args)
        {
            var connectionString = new ConnectionString("http", "localhost", 9200);

            // Create a new Client, that writes the Weater Data and creates the Index weather_data:
            var client = new ElasticSearchClient <ElasticLocalWeatherDataType>(connectionString, "weather_data");

            // Creates the Index, if neccessary:
            client.CreateIndex();

            // Bulk Insert Data:
            foreach (var batch in GetData().Batch(100))
            {
                var response = client.BulkInsert(batch);
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// https://www.elastic.co/guide/en/elasticsearch/reference/master/tune-for-indexing-speed.html
        /// </summary>
        /// <param name="csvFilePath"></param>
        private static void ProcessLocalWeatherData(string csvFilePath)
        {
            if (log.IsInfoEnabled)
            {
                log.Info($"Processing File: {csvFilePath}");
            }

            // Construct the Batch Processor:
            var client = new ElasticSearchClient <Elastic.Model.LocalWeatherData>(ConnectionString, "weather_data");

            // We are creating the Index with special indexing options for initial load,
            // as suggested in the Elasticsearch documentation at [1].
            //
            // We disable the performance-heavy indexing during the initial load and also
            // disable any replicas of the data. This comes at a price of not being able
            // to query the data in realtime, but it will enhance the import speed.
            //
            // After the initial load I will revert to the standard settings for the Index
            // and set the default values for Shards and Refresh Interval.
            //
            // [1]: https://www.elastic.co/guide/en/elasticsearch/reference/master/tune-for-indexing-speed.html
            //
            client.CreateIndex(settings => settings
                               .NumberOfReplicas(0)
                               .RefreshInterval(-1));

            // Access to the List of Parsers:
            var batches = Parsers
                          // Use the LocalWeatherData Parser:
                          .LocalWeatherDataParser
                          // Read the File, Skip first row:
                          .ReadFromFile(csvFilePath, Encoding.UTF8, 1)
                          // Get the Valid Results:
                          .Where(x => x.IsValid)
                          // And get the populated Entities:
                          .Select(x => x.Result)
                          // Convert to ElasticSearch Entity:
                          .Select(x => LocalWeatherDataConverter.Convert(x))
                          // Batch Entities:
                          .Batch(30000);


            foreach (var batch in batches)
            {
                client.BulkInsert(batch);
            }
        }
Пример #4
0
        public static void Main(string[] args)
        {
            var uri = new Uri("http://localhost:9200");

            // Create a new Client, that writes the Weater Data and creates the Index weather_data:
            var client = new ElasticSearchClient <ElasticLocalWeatherDataType>(uri, "weather_data");

            // Creates the Index, if neccessary:
            client.CreateIndex();

            // Bulk Insert Data:
            foreach (var batch in GetData().Batch(100))
            {
                var response = client.BulkInsert(batch);

                if (response.Errors)
                {
                    Console.Error.WriteLine($"Bulk Write failed. Reason: {response.OriginalException.Message}");
                }
            }
        }