Пример #1
0
        public virtual void DeleteIndexes(IElasticClient client, IEnumerable <IElasticIndex> indexes = null)
        {
            if (indexes == null)
            {
                indexes = GetIndexes();
            }

            foreach (var idx in indexes)
            {
                IIndicesResponse deleteResponse;

                var templatedIndex = idx as ITemplatedElasticIndex;
                if (templatedIndex != null)
                {
                    deleteResponse = client.DeleteIndex(idx.VersionedName + "-*");

                    if (client.TemplateExists(idx.VersionedName).Exists)
                    {
                        var response = client.DeleteTemplate(idx.VersionedName);
                        Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred deleting the index template.");
                    }
                }
                else
                {
                    deleteResponse = client.DeleteIndex(idx.VersionedName);
                }

                Debug.Assert(deleteResponse.IsValid, deleteResponse.ServerError != null ? deleteResponse.ServerError.Error : "An error occurred deleting the indexes.");
            }
        }
        public void DeleteIndexes(IElasticClient client)
        {
            var deleteResponse = client.DeleteIndex(i => i.AllIndices());

            Debug.Assert(deleteResponse.IsValid, deleteResponse.ServerError != null ? deleteResponse.ServerError.Error : "An error occurred deleting the indexes.");

            foreach (var index in GetIndexes())
            {
                var templatedIndex = index as ITemplatedElasticSeachIndex;
                if (templatedIndex != null)
                {
                    if (client.TemplateExists(index.VersionedName).Exists)
                    {
                        var response = client.DeleteTemplate(index.VersionedName);
                        Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred deleting the index template.");
                    }
                }
            }
        }
        public void DeleteIndexes(IElasticClient client) {
            var deleteResponse = client.DeleteIndex(i => i.AllIndices());
            Debug.Assert(deleteResponse.IsValid, deleteResponse.ServerError != null ? deleteResponse.ServerError.Error : "An error occurred deleting the indexes.");

            foreach (var index in GetIndexes()) {
                var templatedIndex = index as ITemplatedElasticSeachIndex;
                if (templatedIndex != null) {
                    if (client.TemplateExists(index.VersionedName).Exists) {
                        var response = client.DeleteTemplate(index.VersionedName);
                        Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred deleting the index template.");
                    }
                }
            }
        }
Пример #4
0
        public virtual void DeleteIndexes(IElasticClient client, IEnumerable<IElasticIndex> indexes = null) {
            if (indexes == null)
                indexes = GetIndexes();
            
            foreach (var idx in indexes) {
                IIndicesResponse deleteResponse;

                var templatedIndex = idx as ITemplatedElasticIndex;
                if (templatedIndex != null) {
                    deleteResponse = client.DeleteIndex(idx.VersionedName + "-*");

                    if (client.TemplateExists(idx.VersionedName).Exists) {
                        var response = client.DeleteTemplate(idx.VersionedName);
                        Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred deleting the index template.");
                    }
                } else {
                    deleteResponse = client.DeleteIndex(idx.VersionedName);
                }

                Debug.Assert(deleteResponse.IsValid, deleteResponse.ServerError != null ? deleteResponse.ServerError.Error : "An error occurred deleting the indexes.");
            }
        }
Пример #5
0
        public static void ConfigureMapping(IElasticClient searchclient, bool deleteExistingIndexes = false)
        {
            IIndicesOperationResponse response;

            if (deleteExistingIndexes)
            {
                var deleteResponse = searchclient.DeleteIndex(i => i.AllIndices());
                Debug.Assert(deleteResponse.IsValid, deleteResponse.ServerError != null ? deleteResponse.ServerError.Error : "An error occurred deleting the indexes.");

                response = searchclient.DeleteTemplate(ElasticSearchRepository <PersistentEvent> .EventsIndexName);
                Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred deleting the event index template.");
            }

            if (!searchclient.IndexExists(new IndexExistsRequest(new IndexNameMarker {
                Name = ElasticSearchRepository <Stack> .StacksIndexName
            })).Exists)
            {
                response = searchclient.CreateIndex(ElasticSearchRepository <Stack> .StacksIndexName, d => d
                                                    .AddAlias("stacks")
                                                    .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("first"))
                                                                                    .Date(f => f.Name(s => s.LastOccurrence).IndexName("last"))
                                                                                    .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"))
                                                                                    )
                                                                        )
                                                    );

                Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred creating the stack index.");
            }

            response = searchclient.PutTemplate(ElasticSearchRepository <PersistentEvent> .EventsIndexName, d => d
                                                .Template(ElasticSearchRepository <PersistentEvent> .EventsIndexName + "-*")
                                                .Settings(s => s.Add("analysis", BuildAnalysisSettings()))
                                                .AddMapping <PersistentEvent>(map => map
                                                                              .Dynamic(DynamicMappingOption.Ignore)
                                                                              .IncludeInAll(false)
                                                                              .DisableSizeField(false)
                                                                              .Transform(t => t.Script(FLATTEN_ERRORS_SCRIPT).Language(ScriptLang.Groovy))
                                                                              .AllField(i => i.IndexAnalyzer("standardplus").SearchAnalyzer("whitespace_lower"))
                                                                              .Properties(p => p
                                                                                          .String(f => f.Name(e => e.Id).IndexName("id").Index(FieldIndexOption.NotAnalyzed).IncludeInAll())
                                                                                          .String(f => f.Name(e => e.OrganizationId).IndexName("organization").Index(FieldIndexOption.NotAnalyzed))
                                                                                          .String(f => f.Name(e => e.ProjectId).IndexName("project").Index(FieldIndexOption.NotAnalyzed))
                                                                                          .String(f => f.Name(e => e.StackId).IndexName("stack").Index(FieldIndexOption.NotAnalyzed))
                                                                                          .String(f => f.Name(e => e.ReferenceId).IndexName("reference").Index(FieldIndexOption.Analyzed))
                                                                                          .String(f => f.Name(e => e.SessionId).IndexName("session").Index(FieldIndexOption.Analyzed))
                                                                                          .String(f => f.Name(e => e.Type).IndexName("type").Index(FieldIndexOption.Analyzed))
                                                                                          .String(f => f.Name(e => e.Source).IndexName("source").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                                                          .Date(f => f.Name(e => e.Date).IndexName("date"))
                                                                                          .String(f => f.Name(e => e.Message).IndexName("message").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                                                          .String(f => f.Name(e => e.Tags).IndexName("tag").Index(FieldIndexOption.Analyzed).IncludeInAll().Boost(1.2))
                                                                                          .GeoPoint(f => f.Name(e => e.Geo).IndexLatLon())
                                                                                          .Number(f => f.Name(e => e.Value).IndexName("value"))
                                                                                          .Boolean(f => f.Name(e => e.IsFirstOccurrence).IndexName("first"))
                                                                                          .Boolean(f => f.Name(e => e.IsFixed).IndexName("fixed"))
                                                                                          .Boolean(f => f.Name(e => e.IsHidden).IndexName("hidden"))
                                                                                          .Object <object>(f => f.Name("idx").Dynamic())
                                                                                          .Object <DataDictionary>(f => f.Name(e => e.Data).Path("just_name").Properties(p2 => p2
                                                                                                                                                                         .String(f2 => f2.Name(Event.KnownDataKeys.Version).IndexName("version").Index(FieldIndexOption.Analyzed).IndexAnalyzer("version_index").SearchAnalyzer("version_search"))
                                                                                                                                                                         .String(f2 => f2.Name(Event.KnownDataKeys.Level).IndexName("level").Index(FieldIndexOption.Analyzed))
                                                                                                                                                                         .Object <RequestInfo>(f2 => f2.Name(Event.KnownDataKeys.RequestInfo).Path("just_name").Properties(p3 => p3
                                                                                                                                                                                                                                                                           .String(f3 => f3.Name(r => r.ClientIpAddress).IndexName("ip").Index(FieldIndexOption.Analyzed).IncludeInAll().Analyzer("comma_whitespace"))
                                                                                                                                                                                                                                                                           .String(f3 => f3.Name(r => r.UserAgent).IndexName("useragent").Index(FieldIndexOption.Analyzed))
                                                                                                                                                                                                                                                                           .String(f3 => f3.Name(r => r.Path).IndexName("path").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                                                                                                                                                                                                                                           .Object <DataDictionary>(f3 => f3.Name(e => e.Data).Path("just_name").Properties(p4 => p4
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.Browser).IndexName("browser").Index(FieldIndexOption.Analyzed)
                                                                                                                                                                                                                                                                                                                                                                    .Fields(fields => fields.String(ss => ss.Name("browser.raw").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.BrowserVersion).IndexName("browser.version").Index(FieldIndexOption.Analyzed)
                                                                                                                                                                                                                                                                                                                                                                    .Fields(fields => fields.String(ss => ss.Name("browser.version.raw").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.BrowserMajorVersion).IndexName("browser.major").Index(FieldIndexOption.NotAnalyzed))
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.Device).IndexName("device").Index(FieldIndexOption.Analyzed)
                                                                                                                                                                                                                                                                                                                                                                    .Fields(fields => fields.String(ss => ss.Name("device.raw").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.OS).IndexName("os").Index(FieldIndexOption.Analyzed)
                                                                                                                                                                                                                                                                                                                                                                    .Fields(fields => fields.String(ss => ss.Name("os.raw").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.OSVersion).IndexName("os.version").Index(FieldIndexOption.Analyzed)
                                                                                                                                                                                                                                                                                                                                                                    .Fields(fields => fields.String(ss => ss.Name("os.version.raw").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                                                                                                                                                                                                            .String(f4 => f4.Name(RequestInfo.KnownDataKeys.OSMajorVersion).IndexName("os.major").Index(FieldIndexOption.NotAnalyzed))
                                                                                                                                                                                                                                                                                                                                                            .Boolean(f4 => f4.Name(RequestInfo.KnownDataKeys.IsBot).IndexName("bot"))))))
                                                                                                                                                                         .Object <Error>(f2 => f2.Name(Event.KnownDataKeys.Error).Path("just_name").Properties(p3 => p3
                                                                                                                                                                                                                                                               .String(f3 => f3.Name("all_codes").IndexName("error.code").Index(FieldIndexOption.NotAnalyzed).Analyzer("whitespace").IncludeInAll().Boost(1.1))
                                                                                                                                                                                                                                                               .String(f3 => f3.Name("all_messages").IndexName("error.message").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                                                                                                                                                                                                                               .Object <DataDictionary>(f4 => f4.Name(e => e.Data).Path("just_name").Properties(p4 => p4
                                                                                                                                                                                                                                                                                                                                                .Object <object>(f5 => f5.Name(Error.KnownDataKeys.TargetInfo).Path("just_name").Properties(p5 => p5
                                                                                                                                                                                                                                                                                                                                                                                                                                            .String(f6 => f6.Name("ExceptionType").IndexName("error.targettype").Index(FieldIndexOption.Analyzed).IndexAnalyzer("typename").SearchAnalyzer("whitespace_lower").IncludeInAll().Boost(1.2)
                                                                                                                                                                                                                                                                                                                                                                                                                                                    .Fields(fields => fields.String(ss => ss.Name("error.targettype.raw").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                                                                                                                                                                                                                                                                                            .String(f6 => f6.Name("Method").IndexName("error.targetmethod").Index(FieldIndexOption.Analyzed).IndexAnalyzer("typename").SearchAnalyzer("whitespace_lower").IncludeInAll().Boost(1.2))))))
                                                                                                                                                                                                                                                               .String(f3 => f3.Name("all_types").IndexName("error.type").Index(FieldIndexOption.Analyzed).IndexAnalyzer("typename").SearchAnalyzer("whitespace_lower").IncludeInAll().Boost(1.1))))
                                                                                                                                                                         .Object <SimpleError>(f2 => f2.Name(Event.KnownDataKeys.SimpleError).Path("just_name").Properties(p3 => p3
                                                                                                                                                                                                                                                                           .String(f3 => f3.Name("all_messages").IndexName("error.message").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                                                                                                                                                                                                                                           .Object <DataDictionary>(f4 => f4.Name(e => e.Data).Path("just_name").Properties(p4 => p4
                                                                                                                                                                                                                                                                                                                                                            .Object <object>(f5 => f5.Name(Error.KnownDataKeys.TargetInfo).Path("just_name").Properties(p5 => p5
                                                                                                                                                                                                                                                                                                                                                                                                                                                        .String(f6 => f6.Name("ExceptionType").IndexName("error.targettype").Index(FieldIndexOption.Analyzed).IndexAnalyzer("typename").SearchAnalyzer("whitespace_lower").IncludeInAll().Boost(1.2))))))
                                                                                                                                                                                                                                                                           .String(f3 => f3.Name("all_types").IndexName("error.type").Index(FieldIndexOption.Analyzed).IndexAnalyzer("typename").SearchAnalyzer("whitespace_lower").IncludeInAll().Boost(1.1))))
                                                                                                                                                                         .Object <EnvironmentInfo>(f2 => f2.Name(Event.KnownDataKeys.EnvironmentInfo).Path("just_name").Properties(p3 => p3
                                                                                                                                                                                                                                                                                   .String(f3 => f3.Name(r => r.IpAddress).IndexName("ip").Index(FieldIndexOption.Analyzed).IncludeInAll().Analyzer("comma_whitespace"))
                                                                                                                                                                                                                                                                                   .String(f3 => f3.Name(r => r.MachineName).IndexName("machine").Index(FieldIndexOption.Analyzed).IncludeInAll().Boost(1.1))
                                                                                                                                                                                                                                                                                   .String(f3 => f3.Name(r => r.OSName).IndexName("os").Index(FieldIndexOption.Analyzed))
                                                                                                                                                                                                                                                                                   .String(f3 => f3.Name(r => r.Architecture).IndexName("architecture").Index(FieldIndexOption.NotAnalyzed))))
                                                                                                                                                                         .Object <UserDescription>(f2 => f2.Name(Event.KnownDataKeys.UserDescription).Path("just_name").Properties(p3 => p3
                                                                                                                                                                                                                                                                                   .String(f3 => f3.Name(r => r.Description).IndexName("user.description").Index(FieldIndexOption.Analyzed).IncludeInAll())
                                                                                                                                                                                                                                                                                   .String(f3 => f3.Name(r => r.EmailAddress).IndexName("user.email").Index(FieldIndexOption.Analyzed).IndexAnalyzer("email").SearchAnalyzer("simple").IncludeInAll().Boost(1.1))))
                                                                                                                                                                         .Object <UserInfo>(f2 => f2.Name(Event.KnownDataKeys.UserInfo).Path("just_name").Properties(p3 => p3
                                                                                                                                                                                                                                                                     .String(f3 => f3.Name(r => r.Identity).IndexName("user").Index(FieldIndexOption.Analyzed).IndexAnalyzer("email").SearchAnalyzer("whitespace_lower").IncludeInAll().Boost(1.1))
                                                                                                                                                                                                                                                                     .String(f3 => f3.Name(r => r.Name).IndexName("user.name").Index(FieldIndexOption.Analyzed).IncludeInAll())))))
                                                                                          )
                                                                              )
                                                );

            Debug.Assert(response.IsValid, response.ServerError != null ? response.ServerError.Error : "An error occurred creating the event index template");
        }