Ejemplo n.º 1
0
        public virtual CreateIndexDescriptor CreateIndex(CreateIndexDescriptor idx)
        {
            const string SET_FIXED_SCRIPT = @"ctx._source['fixed'] = !!ctx._source['date_fixed']";

            return(idx.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"))
                                                      )));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public CreateIndexDescriptor CreateIndex(CreateIndexDescriptor idx)
 {
     return(idx.AddMapping <Employee>(GetEmployeeMap));
 }
 public sealed override void ContributeCore(CreateIndexDescriptor descriptor, IElasticClient client)
 {
     descriptor.AddMapping <TType>(MappingCore);
 }
Ejemplo n.º 5
0
 public virtual CreateIndexDescriptor Configure(CreateIndexDescriptor idx)
 {
     return(idx.AddMapping <T>(BuildMapping));
 }