Ejemplo n.º 1
0
 private void SetDirectStreaming(ConnectionSettings settings, ButlerElasticOptions options)
 {
     if (options.DisableDirectStreaming)
     {
         settings.DisableDirectStreaming();
     }
 }
Ejemplo n.º 2
0
        protected virtual void ConfigureClient(ButlerElasticOptions config)
        {
            if (config.Uris == null || !config.Uris.Any())
            {
                throw new Exception("No ElasticSearch URIs configured");
            }

            ConnectionSettings settings = null;

            if (config.Uris.Length > 1)
            {
                var connectionPool = new SniffingConnectionPool(config.Uris.Select(uri => new Uri(uri)));
                settings = new ConnectionSettings(connectionPool)
                           .DefaultIndex(config.DefaultIndex);
            }
            else
            {
                settings = new ConnectionSettings(new Uri(config.Uris.First()))
                           .DefaultIndex(config.DefaultIndex)
                           .DisableDirectStreaming();
            }

            SetDirectStreaming(settings, config);
            Client = new ElasticClient(settings);
        }
Ejemplo n.º 3
0
        protected virtual void Initialize(ButlerElasticOptions config)
        {
            var sets = this.GetType().GetProperties().Where(p => p.PropertyType.IsGenericType && p.PropertyType.Name.StartsWith("ElasticSet"));

            foreach (var set in sets)
            {
                var type = set.PropertyType;

                var    elasticSetType  = typeof(ElasticSet <>);
                Type[] typeParameters  = type.GetGenericArguments();
                var    constructedType = elasticSetType.MakeGenericType(typeParameters);

                // Get index of ElasticIndex attribute or fall back to the property name on the ElasticContext
                string rawIndex = GetRawIndex(set);

                var obj = Activator.CreateInstance(constructedType, GetIndexWithPrefixAndSuffix(rawIndex), Client, GetIndexSettings(rawIndex), GetIndexMappings(rawIndex));
                set.SetValue(this, obj, null);

                var createIndexMethod = constructedType.GetMethod("CreateIndex");
                createIndexMethod.Invoke(obj, new object[] { });
            }
        }
Ejemplo n.º 4
0
 public ElasticContext(IOptions <ButlerElasticOptions> options)
 {
     ElasticOptions = options.Value;
     ConfigureClient(options.Value);
 }
Ejemplo n.º 5
0
 private Dictionary <string, Func <MappingsDescriptor, IPromise <IMappings> > > GetIndexMappings(ButlerElasticOptions options)
 {
     return(new Dictionary <string, Func <MappingsDescriptor, IPromise <IMappings> > >
     {
         { Indexes.Examples, m => m.Map <ExampleDocument>(mc => mc.AutoMap()
                                                          .Properties(p => p
                                                                      .Text(
                                                                          t => t
                                                                          .Name(n => n.Name)
                                                                          .Analyzer(NgramAnalyzer)
                                                                          .Fields(f => f
                                                                                  .Keyword(k => k
                                                                                           .Name(Keyword)
                                                                                           .IgnoreAbove(256))
                                                                                  .Keyword(k => k
                                                                                           .Name(Lowercase)
                                                                                           .IgnoreAbove(256)
                                                                                           .Normalizer(KeywordLowercaseNormalizer))
                                                                                  ))
                                                                      .Text(t => t
                                                                            .Name(n => n.Description)
                                                                            .Fields(f => f
                                                                                    .Keyword(k => k
                                                                                             .Name(Lowercase)
                                                                                             .Normalizer(KeywordLowercaseNormalizer))
                                                                                    ))
                                                                      )) }
     });
 }
Ejemplo n.º 6
0
 private Dictionary <string, Func <IndexSettingsDescriptor, IPromise <IIndexSettings> > > GetIndexSettings(ButlerElasticOptions options)
 {
     return(new Dictionary <string, Func <IndexSettingsDescriptor, IPromise <IIndexSettings> > >
     {
         { Indexes.Examples, s => s
           .Analysis(a => a
                     .Normalizers(n => n
                                  .Custom(KeywordLowercaseNormalizer, cs => cs.Filters(Lowercase)))
                     .Analyzers(an => an
                                .Custom(NgramAnalyzer, ca => ca
                                        .Tokenizer("ngram")
                                        .Filters("standard"))))
           .NumberOfShards(options.NumberOfShards).NumberOfReplicas(options.NumberOfReplicas) }
     });
 }