Exemplo n.º 1
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);
        }
 public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
 {
     if (_shards.HasValue && _shards.Value > 0)
     {
         descriptor.NumberOfShards(_shards.Value);
     }
 }
Exemplo n.º 3
0
        public virtual CreateIndexDescriptor CreateIndex(CreateIndexDescriptor idx)
        {
            const string SET_FIXED_SCRIPT = @"ctx._source['fixed'] = !!ctx._source['date_fixed']";

            return(idx
                   .NumberOfShards(Settings.Current.ElasticSearchNumberOfShards)
                   .NumberOfReplicas(Settings.Current.ElasticSearchNumberOfReplicas)
                   .AddMapping <Stack>(map => map
                                       .Dynamic(DynamicMappingOption.Ignore)
                                       .Transform(t => t.Script(SET_FIXED_SCRIPT).Language(ScriptLang.Groovy))
                                       .IncludeInAll(false)
                                       .Properties(p => p
                                                   .String(f => f.Name(e => e.Id).IndexName("id").Index(FieldIndexOption.NotAnalyzed).IncludeInAll())
                                                   .String(f => f.Name(s => s.OrganizationId).IndexName("organization").Index(FieldIndexOption.NotAnalyzed))
                                                   .String(f => f.Name(s => s.ProjectId).IndexName("project").Index(FieldIndexOption.NotAnalyzed))
                                                   .String(f => f.Name(s => s.SignatureHash).IndexName("signature").Index(FieldIndexOption.NotAnalyzed))
                                                   .String(f => f.Name(e => e.Type).IndexName("type").Index(FieldIndexOption.NotAnalyzed))
                                                   .Date(f => f.Name(s => s.FirstOccurrence).IndexName(Fields.Stack.FirstOccurrence))
                                                   .Date(f => f.Name(s => s.LastOccurrence).IndexName(Fields.Stack.LastOccurrence))
                                                   .String(f => f.Name(s => s.Title).IndexName("title").Index(FieldIndexOption.Analyzed).IncludeInAll().Boost(1.1))
                                                   .String(f => f.Name(s => s.Description).IndexName("description").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                   .String(f => f.Name(s => s.Tags).IndexName("tag").Index(FieldIndexOption.Analyzed).IncludeInAll().Boost(1.2))
                                                   .String(f => f.Name(s => s.References).IndexName("links").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                   .Date(f => f.Name(s => s.DateFixed).IndexName("fixedon"))
                                                   .Boolean(f => f.Name("fixed"))
                                                   .Boolean(f => f.Name(s => s.IsHidden).IndexName("hidden"))
                                                   .Boolean(f => f.Name(s => s.IsRegressed).IndexName("regressed"))
                                                   .Boolean(f => f.Name(s => s.OccurrencesAreCritical).IndexName("critical"))
                                                   .Number(f => f.Name(s => s.TotalOccurrences).IndexName("occurrences"))
                                                   )));
        }
 public override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
 {
     if (_shards.HasValue && _shards.Value > 0)
     {
         descriptor.NumberOfShards(_shards.Value);
     }
 }
Exemplo n.º 5
0
 public override CreateIndexDescriptor Configure(CreateIndexDescriptor idx)
 {
     return(idx
            .NumberOfShards(Settings.Current.ElasticSearchNumberOfShards)
            .NumberOfReplicas(Settings.Current.ElasticSearchNumberOfReplicas)
            .Analysis(BuildAnalysis)
            .AddMapping <PersistentEvent>(BuildMapping));
 }
Exemplo n.º 6
0
        public override CreateIndexDescriptor Configure(CreateIndexDescriptor idx)
        {
            var keywordLowercaseAnalyzer = new CustomAnalyzer {
                Filter = new List <string> {
                    "lowercase"
                }, Tokenizer = "keyword"
            };

            return(idx
                   .NumberOfShards(Settings.Current.ElasticSearchNumberOfShards)
                   .NumberOfReplicas(Settings.Current.ElasticSearchNumberOfReplicas)
                   .Analysis(descriptor => descriptor.Analyzers(bases => bases.Add(KEYWORD_LOWERCASE_ANALYZER, keywordLowercaseAnalyzer)))
                   .AddMapping <User>(BuildMapping));
        }
Exemplo n.º 7
0
        public CreateIndexDescriptor CreateIndex(CreateIndexDescriptor idx)
        {
            var keywordLowercaseAnalyzer = new CustomAnalyzer {
                Filter = new List <string> {
                    "lowercase"
                }, Tokenizer = "keyword"
            };

            return(idx.NumberOfShards(Settings.Current.ElasticSearchNumberOfShards)
                   .NumberOfReplicas(Settings.Current.ElasticSearchNumberOfReplicas)
                   .Analysis(descriptor => descriptor.Analyzers(bases => bases.Add(KEYWORD_LOWERCASE, keywordLowercaseAnalyzer)))
                   .AddMapping <Application>(GetApplicationMap)
                   .AddMapping <Organization>(GetOrganizationMap)
                   .AddMapping <Project>(GetProjectMap)
                   .AddMapping <Models.Token>(GetTokenMap)
                   .AddMapping <User>(GetUserMap)
                   .AddMapping <WebHook>(GetWebHookMap));
        }
        public override CreateIndexDescriptor ConfigureDescriptor(CreateIndexDescriptor idx)
        {
            idx = base.ConfigureDescriptor(idx);
            idx.NumberOfShards(3);

            var keywordLowercase = new CustomAnalyzer {
                Filter = new List <string> {
                    "lowercase"
                },
                Tokenizer = "keyword"
            };

            idx
            .Analysis(descriptor => descriptor
                      .Analyzers(bases => bases
                                 .Add("keyword_lowercase", keywordLowercase)
                                 )
                      );

            return(idx);
        }