Esempio n. 1
0
        private object GetTemplateData()
        {
            if (_options.GetTemplateContent != null)
            {
                return(_options.GetTemplateContent());
            }

            var settings = new Dictionary <string, string>
            {
                { "index.refresh_interval", "5s" }
            };

            if (_options.NumberOfShards.HasValue)
            {
                settings.Add("number_of_shards", _options.NumberOfShards.Value.ToString());
            }

            if (_options.NumberOfReplicas.HasValue)
            {
                settings.Add("number_of_replicas", _options.NumberOfReplicas.Value.ToString());
            }

            return(ElasticsearchTemplateProvider.GetTemplate(
                       settings,
                       _templateMatchString,
                       _options.AutoRegisterTemplateVersion));
        }
Esempio n. 2
0
        private object GetTemplateData()
        {
            if (_options.GetTemplateContent != null)
            {
                return(_options.GetTemplateContent());
            }

            var settings = _options.TemplateCustomSettings ?? new Dictionary <string, string>();

            if (!settings.ContainsKey("index.refresh_interval"))
            {
                settings.Add("index.refresh_interval", "5s");
            }

            if (_options.NumberOfShards.HasValue && !settings.ContainsKey("number_of_shards"))
            {
                settings.Add("number_of_shards", _options.NumberOfShards.Value.ToString());
            }

            if (_options.NumberOfReplicas.HasValue && !settings.ContainsKey("number_of_replicas"))
            {
                settings.Add("number_of_replicas", _options.NumberOfReplicas.Value.ToString());
            }

            return(ElasticsearchTemplateProvider.GetTemplate(
                       _options,
                       DiscoveredVersion,
                       settings,
                       _templateMatchString,
                       _options.AutoRegisterTemplateVersion));
        }
Esempio n. 3
0
        /// <summary>
        /// Register the elasticsearch index template if the provided options mandate it.
        /// </summary>
        public void RegisterTemplateIfNeeded()
        {
            if (!this._registerTemplateOnStartup)
            {
                return;
            }

            try
            {
                if (!this._options.OverwriteTemplate)
                {
                    var templateExistsResponse = this._client.IndicesExistsTemplateForAll <DynamicResponse>(this._templateName);
                    if (templateExistsResponse.HttpStatusCode == 200)
                    {
                        return;
                    }
                }

                if (_options.GetTemplateContent != null)
                {
                    this._client.IndicesPutTemplateForAll <DynamicResponse>(this._templateName, _options.GetTemplateContent());
                }
                else
                {
                    var settings = new Dictionary <string, string>
                    {
                        { "index.refresh_interval", "5s" }
                    };

                    if (_options.NumberOfShards.HasValue)
                    {
                        settings.Add("number_of_shards", _options.NumberOfShards.Value.ToString());
                    }

                    var result = this._client.IndicesPutTemplateForAll <DynamicResponse>(this._templateName, new
                    {
                        template = this._templateMatchString,
                        settings = settings,
                        mappings = new
                        {
                            _default_ = new
                            {
                                _all = new { enabled = true, omit_norms = true },
                                dynamic_templates = new List <Object>
                                {
                                    //when you use serilog as an adaptor for third party frameworks
                                    //where you have no control over the log message they typically
                                    //contain {0} ad infinitum, we force numeric property names to
                                    //contain strings by default.
                                    { new { numerics_in_fields = new
                                            {
                                                path_match    = @"fields\.[\d+]$",
                                                match_pattern = "regex",
                                                mapping       = new
                                                {
                                                    type = "string", index = "analyzed", omit_norms = true
                                                }
                                            } } },
                                    {
                                        new { string_fields = new
                                              {
                                                  match = "*",
                                                  match_mapping_type = "string",
                                                  mapping            = new
                                                  {
                                                      type   = "string", index = "analyzed", omit_norms = true,
                                                      fields = new
                                                      {
                                                          raw = new
                                                          {
                                                              type = "string", index = "not_analyzed", ignore_above = 256
                                                          }
                                                      }
                                                  }
                                              } }
                                    }
                                },
                                properties = new Dictionary <string, object>
                                {
                                    { "message", new { type = "string", index = "analyzed" } },
                                    { "exceptions", new
                                      {
                                          type = "nested", properties = new Dictionary <string, object>
                                          {
                                              { "Depth", new { type = "integer" } },
                                              { "RemoteStackIndex", new { type = "integer" } },
                                              { "HResult", new { type = "integer" } },
                                              { "StackTraceString", new { type = "string", index = "analyzed" } },
                                              { "RemoteStackTraceString", new { type = "string", index = "analyzed" } },
                                              { "ExceptionMessage", new
                                            {
                                                type = "object", properties = new Dictionary <string, object>
                                                {
                                                    { "MemberType", new { type = "integer" } },
                                                }
                                            } }
                                          }
                                      } }
                                }
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("Failed to create the template. {0}", ex);
            }
        }
Esempio n. 4
0
        private object GetTemplateData()
        {
            if (_options.GetTemplateContent != null)
            {
                return(_options.GetTemplateContent());
            }

            var settings = new Dictionary <string, string>
            {
                { "index.refresh_interval", "5s" }
            };

            if (_options.NumberOfShards.HasValue)
            {
                settings.Add("number_of_shards", _options.NumberOfShards.Value.ToString());
            }

            if (_options.NumberOfReplicas.HasValue)
            {
                settings.Add("number_of_replicas", _options.NumberOfReplicas.Value.ToString());
            }

            return(new
            {
                template = this._templateMatchString,
                settings = settings,
                mappings = new
                {
                    _default_ = new
                    {
                        _all = new { enabled = true, omit_norms = true },
                        dynamic_templates = new List <Object>
                        {
                            //when you use serilog as an adaptor for third party frameworks
                            //where you have no control over the log message they typically
                            //contain {0} ad infinitum, we force numeric property names to
                            //contain strings by default.
                            {
                                new
                                {
                                    numerics_in_fields = new
                                    {
                                        path_match = @"fields\.[\d+]$",
                                        match_pattern = "regex",
                                        mapping = new
                                        {
                                            type = "string",
                                            index = "analyzed",
                                            omit_norms = true
                                        }
                                    }
                                }
                            },
                            {
                                new
                                {
                                    string_fields = new
                                    {
                                        match = "*",
                                        match_mapping_type = "string",
                                        mapping = new
                                        {
                                            type = "string",
                                            index = "analyzed",
                                            omit_norms = true,
                                            fields = new
                                            {
                                                raw = new
                                                {
                                                    type = "string",
                                                    index = "not_analyzed",
                                                    ignore_above = 256
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        properties = new Dictionary <string, object>
                        {
                            { "message", new { type = "string", index = "analyzed" } },
                            {
                                "exceptions", new
                                {
                                    type = "nested",
                                    properties = new Dictionary <string, object>
                                    {
                                        { "Depth", new { type = "integer" } },
                                        { "RemoteStackIndex", new { type = "integer" } },
                                        { "HResult", new { type = "integer" } },
                                        { "StackTraceString", new { type = "string", index = "analyzed" } },
                                        { "RemoteStackTraceString", new { type = "string", index = "analyzed" } },
                                        {
                                            "ExceptionMessage", new
                                            {
                                                type = "object",
                                                properties = new Dictionary <string, object>
                                                {
                                                    { "MemberType", new { type = "integer" } },
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }