public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
 {
     if (_replicas.HasValue && _replicas >= 0)
     {
         descriptor.NumberOfReplicas(_replicas.Value);
     }
 }
Пример #2
0
        /// <summary>
        /// Create index
        /// </summary>
        /// <typeparam name="T">Index type</typeparam>
        /// <param name="index">Index name</param>
        /// <param name="numberOfShards">Number of shards</param>
        /// <param name="numberOfReplicas">Number of replicas</param>
        /// <param name="force">Force</param>
        /// <param name="languageCode">Language Code Enum</param>
        ///
        public bool CreateIndex <T>(string index, int numberOfShards, int numberOfReplicas, bool force = false, LanguageCode languageCode = LanguageCode.EN)
            where T : class
        {
            var descriptor = new CreateIndexDescriptor(_connectionSettings);

            descriptor.NumberOfShards(numberOfShards);
            descriptor.NumberOfReplicas(numberOfReplicas);

            var analysis = _analysisResolver.Resolve <T>(languageCode);

            if (analysis != null)
            {
                descriptor.Analysis(a => analysis);
            }

            // Add any custom analyzers
            _analyzerResolver = new ElasticsearchAnalyzerResolver();
            if (_analysisResolver != null)
            {
                descriptor = _analyzerResolver.Resolve <T>(descriptor);
            }

            var mapping = _mappingResolver.Resolve <T>(_connectionSettings);

            if (mapping != null)
            {
                descriptor.AddMapping <T>(m => mapping);
            }

            var success = CreateIndex(index, descriptor, force);

            return(success);
        }