Ejemplo n.º 1
0
        /// <summary>
        ///     Reindex constructor. The class reuires a index and a type for the old index and also
        ///     the new index. The old index can then be converteds or reindexed to the new index.
        /// </summary>
        /// <param name="oldIndexTypeDescription">
        ///     index and index type parameters for the old index
        /// </param>
        /// <param name="newIndexTypeDescription">
        ///     index and index type parameters for the new index
        /// </param>
        /// <param name="connectionString">        Elastic connection string </param>
        public ElasticReindex(IndexTypeDescription oldIndexTypeDescription,
                              IndexTypeDescription newIndexTypeDescription, string connectionString)
        {
            _oldIndexTypeDescription = oldIndexTypeDescription;
            _newIndexTypeDescription = newIndexTypeDescription;
            IElasticMappingResolver elasticMappingResolver = new ElasticMappingResolver();

            elasticMappingResolver.AddElasticSearchMappingForEntityType(typeof(TNew),
                                                                        MappingUtils.GetElasticMapping <TNew>(newIndexTypeDescription));
            elasticMappingResolver.AddElasticSearchMappingForEntityType(typeof(TOld),
                                                                        MappingUtils.GetElasticMapping <TOld>(oldIndexTypeDescription));
            _context = new ElasticContext(connectionString, elasticMappingResolver);
        }
Ejemplo n.º 2
0
        internal static void BuildConfig(this IConfiguration configuration, string configSection = DefaultConfigSection)
        {
            var isHaveConfig = configuration.GetChildren().Any(x => x.Key == configSection);

            if (isHaveConfig)
            {
                ElasticConfig.ConnectionString = configuration.GetValue($"{configSection}:{nameof(ElasticConfig.ConnectionString)}", ElasticConfig.ConnectionString);
            }

            try
            {
                using (ElasticContext context = new ElasticContext())
                {
                }
            }
            catch (Exception)
            {
                throw new ElasticException("Cannot connect to elastic, please install elastic");
            }
        }