Ejemplo n.º 1
0
        public void CreateIndex()
        {
            if (indexQuery.IsExists(Constants.SlambyMetadataIndex))
            {
                return;
            }

            var client = elasticClientFactory.GetClient();

            var descriptor = new CreateIndexDescriptor(Constants.SlambyMetadataIndex);

            descriptor
            .Settings(s => s
                      .NumberOfReplicas(0)
                      .NumberOfShards(1))
            .Mappings(m => m
                      .Map <MetadataElastic>(mm => mm
                                             .AutoMap()
                                             .Dynamic(false)
                                             ));

            var createResp = client.CreateIndex(descriptor);

            ResponseValidator(createResp);

            var metadataElastic = new MetadataElastic()
            {
                DBVersion = 0
            };

            Index(metadataElastic);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 设置shards和replicas和model搜索deep
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="x"></param>
 /// <param name="shards"></param>
 /// <param name="replicas"></param>
 /// <param name="deep"></param>
 /// <returns></returns>
 public static CreateIndexDescriptor GetCreateIndexDescriptor <T>(this CreateIndexDescriptor x,
                                                                  int shards = 5, int replicas = 1, int deep = 5)
     where T : class, IElasticSearchIndex
 {
     return(x.Settings(s =>
                       s.NumberOfShards(shards).NumberOfReplicas(replicas)).Mappings(map => map.Map <T>(m => m.AutoMap(deep))));
 }
Ejemplo n.º 3
0
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s
                                             .NumberOfShards(_settings.ElasticsearchNumberOfShards)
                                             .NumberOfReplicas(_settings.ElasticsearchNumberOfReplicas)
                                             .Priority(5))));
 }
Ejemplo n.º 4
0
        public void CreateIndex()
        {
            if (indexQuery.IsExists(Constants.SlambyProcessesIndex))
            {
                return;
            }

            var client = elasticClientFactory.GetClient();

            var descriptor = new CreateIndexDescriptor(Constants.SlambyProcessesIndex);

            descriptor
            .Settings(s => s.
                      NumberOfReplicas(0)
                      .NumberOfShards(1))
            .Mappings(m => m
                      .Map <ProcessElastic>(mm => mm.AutoMap().Dynamic(false))
                      );

            var createResp = client.CreateIndex(descriptor);

            ResponseValidator(createResp);

            var propDesc = new PropertiesDescriptor <ProcessElastic>();

            propDesc.Object <object>(s => s.Name(ProcessElastic.InitObjectMappingName).Dynamic(true));
            var putMappingDesc = new PutMappingDescriptor <ProcessElastic>()
                                 .Index(Constants.SlambyProcessesIndex)
                                 .Dynamic(DynamicMapping.Strict)
                                 .Properties(p => propDesc);
            var mapResp = client.Map <DocumentElastic>(p => putMappingDesc);

            ResponseValidator(mapResp);
        }
Ejemplo n.º 5
0
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s
                                             .NumberOfShards(_configuration.Options.NumberOfShards)
                                             .NumberOfReplicas(_configuration.Options.NumberOfReplicas)
                                             .Priority(5))));
 }
Ejemplo n.º 6
0
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s
                                             .Analysis(BuildAnalysis)
                                             .NumberOfShards(Settings.Current.ElasticSearchNumberOfShards)
                                             .NumberOfReplicas(Settings.Current.ElasticSearchNumberOfReplicas)
                                             .Priority(1))));
 }
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s
                                             .Analysis(d => d.Analyzers(b => b.Custom(KEYWORD_LOWERCASE_ANALYZER, c => c.Filters("lowercase").Tokenizer("keyword"))))
                                             .NumberOfShards(_configuration.Options.NumberOfShards)
                                             .NumberOfReplicas(_configuration.Options.NumberOfReplicas)
                                             .Priority(10))));
 }
 protected virtual ICreateIndexRequest CreateFluent(string indexName, CreateIndexDescriptor c) =>
 c.Settings(s => s
            .Analysis(a => a
                      .Analyzers(t => Promise(AnalysisUsageTests.AnalyzersFluent.Analysis.Analyzers))
                      .CharFilters(t => Promise(AnalysisUsageTests.CharFiltersFluent.Analysis.CharFilters))
                      .Tokenizers(t => Promise(AnalysisUsageTests.TokenizersFluent.Analysis.Tokenizers))
                      .TokenFilters(t => Promise(AnalysisUsageTests.TokenFiltersFluent.Analysis.TokenFilters))
                      )
            );
Ejemplo n.º 9
0
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s
                                             .Analysis(BuildAnalysis)
                                             .NumberOfShards(Settings.Current.ElasticSearchNumberOfShards)
                                             .NumberOfReplicas(Settings.Current.ElasticSearchNumberOfReplicas)
                                             .Setting("index.mapping.total_fields.limit", Settings.Current.ElasticSearchFieldsLimit)
                                             .Priority(1))));
 }
 protected ICreateIndexRequest CreateFluent(string indexName, CreateIndexDescriptor c) =>
 c.Settings(s => s
            .Analysis(a => a
                      .Analyzers(t => Promise(Analyzers.AnalyzerUsageTests.FluentExample(s).Value.Analysis.Analyzers))
                      .CharFilters(t => Promise(CharFilters.CharFilterUsageTests.FluentExample(s).Value.Analysis.CharFilters))
                      .Tokenizers(t => Promise(Tokenizers.TokenizerUsageTests.FluentExample(s).Value.Analysis.Tokenizers))
                      .TokenFilters(t => Promise(TokenFilters.TokenFilterUsageTests.FluentExample(s).Value.Analysis.TokenFilters))
                      )
            );
Ejemplo n.º 11
0
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s
                                             .Analysis(BuildAnalysis)
                                             .NumberOfShards(_configuration.Options.NumberOfShards)
                                             .NumberOfReplicas(_configuration.Options.NumberOfReplicas)
                                             .Setting("index.mapping.total_fields.limit", _configuration.Options.FieldsLimit)
                                             .Priority(1))));
 }
Ejemplo n.º 12
0
        static void GetCreateIndexDescriptor <T>(CreateIndexDescriptor create_index_descriptor,
                                                 int?shards = null, int?replicas = null, int deep = 5)
            where T : class, IESIndex
        {
            //shards and replicas
            var indexDescriptor = create_index_descriptor.Settings(s => s.NumberOfShards(shards).NumberOfReplicas(replicas));

            //mapping option
            indexDescriptor = indexDescriptor.Map(x => x.AutoMap <T>(maxRecursion: deep).SourceField(s => s.Enabled(false)));
        }
Ejemplo n.º 13
0
        private static CreateIndexDescriptor CreateIndexDescriptor(string indexName, AnalysisDescriptor analysistDescriptor, Func <TypeMappingDescriptor <DocumentElastic>, TypeMappingDescriptor <DocumentElastic> > documentMappingDescriptor)
        {
            var descriptor = new CreateIndexDescriptor(indexName);

            descriptor.Settings(s => s.NumberOfReplicas(0).NumberOfShards(1).Analysis(a => analysistDescriptor))
            .Mappings(mapping => mapping
                      .Map <DocumentElastic>(map => documentMappingDescriptor(map).AutoMap())
                      .Map <TagElastic>(mm => mm.AutoMap().Dynamic(false))
                      .Map <PropertiesElastic>(mm => mm.AutoMap().Dynamic(false)));
            return(descriptor);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 设置shards和replicas和model搜索deep
        /// https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-analyzers.html
        /// 创建自定义分词
        /// </summary>
        public static CreateIndexDescriptor GetCreateIndexDescriptor <T>(this CreateIndexDescriptor create_index_descriptor,
                                                                         int?shards = null, int?replicas = null, int deep = 5)
            where T : class, IESIndex
        {
            //shards and replicas
            var indexDescriptor = create_index_descriptor.Settings(s => s.NumberOfShards(shards).NumberOfReplicas(replicas));

            //mapping option
            indexDescriptor = indexDescriptor.Map(x => x.AutoMap <T>(maxRecursion: deep));

            return(indexDescriptor);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 设置shards和replicas和model搜索deep
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="x"></param>
        /// <param name="shards"></param>
        /// <param name="replicas"></param>
        /// <param name="deep"></param>
        /// <returns></returns>
        public static CreateIndexDescriptor GetCreateIndexDescriptor <T>(this CreateIndexDescriptor x,
                                                                         int?shards = null, int?replicas = null, int deep = 5)
            where T : class, IElasticSearchIndex
        {
            //shards and replicas
            var indexDescriptor = x.Settings(s => s.NumberOfShards(shards).NumberOfReplicas(replicas));

            //mapping option
            indexDescriptor = indexDescriptor.Mappings(map => map.Map <T>(m => m.AutoMap(deep)));

            return(indexDescriptor);
        }
        public static CreateIndexDescriptor CreatePopertyIndexSettingAndMapping(this CreateIndexDescriptor indexDescriptor)
        {
            indexDescriptor.Settings(s => s
                                     .Setting("index.codec", "best_compression")
                                     .Analysis(a =>
                                               a.TokenFilters(t => t
                                                              .Stemmer("english_stemmer", st => st
                                                                       .Language("english")
                                                                       )
                                                              .Stop("custom_stop", stop => stop
                                                                    .StopWords(new string[] { "and", "or", "into", "the" })
                                                                    )
                                                              )
                                               .Analyzers(an => an
                                                          .Custom("main_analyzer", ca => ca
                                                                  .Tokenizer("standard")
                                                                  .Filters("english_stemmer", "custom_stop")
                                                                  )
                                                          )
                                               )
                                     )
            .Map <PropertyES>(m => m
                              .Properties(pr => pr
                                          .Scalar(s => s.Id)
                                          .Text(t => t
                                                .Name(n => n.Name)
                                                .Analyzer("main_analyzer")
                                                )
                                          .Text(t => t
                                                .Name(n => n.FormerName)
                                                .Analyzer("main_analyzer")
                                                )
                                          .Text(t => t
                                                .Name(n => n.StreetAddress)
                                                .Analyzer("main_analyzer")
                                                )
                                          .Text(t => t
                                                .Name(n => n.City)
                                                .Analyzer("main_analyzer")
                                                )
                                          .Keyword(k => k
                                                   .Name(n => n.Market)
                                                   )
                                          .Keyword(k => k
                                                   .Name(n => n.State)
                                                   )
                                          )
                              );

            return(indexDescriptor);
        }
Ejemplo n.º 17
0
 /// <inheritdoc cref="IIndexConfigurator.Configure" />
 public CreateIndexDescriptor Configure(CreateIndexDescriptor descriptor)
 {
     return(descriptor.Settings(s => s.Analysis(y => y
                                                .Analyzers(a => a
                                                           .Custom("code", c => c
                                                                   .Tokenizer("keyword")
                                                                   .Filters("standard"))
                                                           .Custom("text_fr", c => c
                                                                   .Tokenizer("pattern")
                                                                   .Filters("standard", "lowercase", "asciifolding")))
                                                .Tokenizers(w => w
                                                            .Keyword("keyword", t => t)
                                                            .Pattern("pattern", t => t.Pattern(@"([^\p{L}\d^&^-^.]+)"))))));
 }
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx
                                .Settings(s => s.NumberOfReplicas(0).NumberOfShards(1))
                                .Map <IParentChildDocument>(m => m
                                                            //.RoutingField(r => r.Required())
                                                            .AutoMap <Parent>()
                                                            .AutoMap <Child>()
                                                            .Properties(p => p
                                                                        .SetupDefaults()
                                                                        .Join(j => j
                                                                              .Name(n => n.Discriminator)
                                                                              .Relations(r => r.Join <Parent, Child>())
                                                                              )
                                                                        ))));
 }
Ejemplo n.º 19
0
        public void CreateIndex()
        {
            if (indexQuery.IsExists(Constants.SlambyServicesIndex))
            {
                return;
            }

            var descriptor = new CreateIndexDescriptor(Constants.SlambyServicesIndex);

            descriptor
            .Settings(s => s
                      .NumberOfReplicas(0)
                      .NumberOfShards(1))
            .Mappings(m => m
                      .Map <ServiceElastic>(mm => mm.AutoMap().Dynamic(false))
                      .Map <ClassifierSettingsElastic>(mm => mm.AutoMap().Dynamic(false))
                      .Map <PrcSettingsElastic>(mm => mm.AutoMap().Dynamic(false)));

            var createResp = elasticClientFactory.GetClient().CreateIndex(descriptor);

            ResponseValidator(createResp);
        }
Ejemplo n.º 20
0
        public void CreateIndex()
        {
            if (indexQuery.IsExists(Constants.SlambyFileParserIndex))
            {
                return;
            }

            var descriptor = new CreateIndexDescriptor(Constants.SlambyFileParserIndex);

            descriptor
            .Settings(s => s
                      .NumberOfReplicas(0)
                      .NumberOfShards(1))
            .Mappings(m => m
                      .Map <FileParserElastic>(mm => mm
                                               .Properties(
                                                   p => p.Attachment(desc => desc
                                                                     .Name("content")
                                                                     .FileField(d => d //ContentField
                                                                                .Store(true)
                                                                                .Analyzer("standard"))
                                                                     .ContentTypeField(d => d.Store(true))
                                                                     .ContentLengthField(d => (d as NumberPropertyDescriptor <FileParserElastic>).Store(true))
                                                                     .LanguageField(d => (d as StringPropertyDescriptor <FileParserElastic>).Store(true))
                                                                     .KeywordsField(d => d.Store(true))
                                                                     .AuthorField(d => d.Store(true))
                                                                     .DateField(d => d.Store(true))
                                                                     .TitleField(d => d.Store(true))
                                                                     )
                                                   ))
                      );

            var createResp = elasticClientFactory.GetClient().CreateIndex(descriptor);

            ResponseValidator(createResp);
        }
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s.NumberOfReplicas(0).NumberOfShards(1).Analysis(a => a.AddSortNormalizer()))));
 }
 protected override ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor create) => create
 .Settings(s => s
           .Analysis(a => a
                     .CharFilters(t => Promise(AnalysisUsageTests.CharFiltersFluent.Analysis.CharFilters))
                     .TokenFilters(t => Promise(AnalysisUsageTests.TokenFiltersFluent.Analysis.TokenFilters))
                     .Normalizers(t => Promise(AnalysisUsageTests.NormalizersInitializer.Analysis.Normalizers))
                     )
           );
 public override CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
 {
     return(base.ConfigureIndex(idx.Settings(s => s.NumberOfReplicas(0).NumberOfShards(1))));
 }
Ejemplo n.º 24
0
 internal ICreateIndexRequest BuildRequest(CreateIndexDescriptor c)
 {
     return
         (c.Settings(applyIndexSettings)
          .Map(applyTypeMapping));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// 默认的shards和replicas
 /// </summary>
 /// <param name="x"></param>
 /// <returns></returns>
 public static CreateIndexDescriptor DeaultCreateIndexDescriptor <T>(this CreateIndexDescriptor x) where T : class
 {
     return(x.Settings(s => s.NumberOfShards(5).NumberOfReplicas(1)).Mappings(map => map.Map <T>(m => m.AutoMap(5))));
 }
Ejemplo n.º 26
0
 public static CreateIndexDescriptor MoviesIndexDescriptor(CreateIndexDescriptor createIndexDescriptor)
 {
     return(createIndexDescriptor
            .Settings(settings => settings
                      .NumberOfShards(4)
                      .NumberOfReplicas(3)
                      .Setting("index.max_result_window", int.MaxValue)
                      .Analysis(analysis => analysis
                                .Analyzers(a => a
                                           .Custom("text_analyzer", s => s
                                                   .Tokenizer("standard")
                                                   .Filters("lowercase", "asciifolding")
                                                   )
                                           )
                                )
                      )
            .Mappings(mappings => mappings
                      .Map <MovieAdo>(m => m
                                      .Properties(p => p
                                                  .Text(txt => txt
                                                        .Name(name => name.Title)
                                                        .Fields(f => f
                                                                .Text(f_txt => f_txt
                                                                      .Name("search")
                                                                      .Analyzer("text_analyzer")
                                                                      )
                                                                .Keyword(kw => kw
                                                                         .Name("keyword")
                                                                         )
                                                                )
                                                        )
                                                  .Text(txt => txt
                                                        .Name(name => name.Language)
                                                        .Fields(f => f
                                                                .Text(f_txt => f_txt
                                                                      .Name("search")
                                                                      .Analyzer("text_analyzer")
                                                                      )
                                                                .Keyword(kw => kw
                                                                         .Name("keyword")
                                                                         )
                                                                )
                                                        )
                                                  .Text(txt => txt
                                                        .Name(name => name.Director)
                                                        .Fields(f => f
                                                                .Text(f_txt => f_txt
                                                                      .Name("search")
                                                                      .Analyzer("text_analyzer")
                                                                      )
                                                                .Keyword(kw => kw
                                                                         .Name("keyword")
                                                                         )
                                                                )
                                                        )
                                                  .Text(txt => txt
                                                        .Name(name => name.Actors)
                                                        .Fields(f => f
                                                                .Text(f_txt => f_txt
                                                                      .Name("search")
                                                                      .Analyzer("text_analyzer")
                                                                      )
                                                                .Keyword(kw => kw
                                                                         .Name("keyword")
                                                                         )
                                                                )
                                                        )
                                                  .Number(numb => numb
                                                          .Name(name => name.MovieId)
                                                          .Type(NumberType.Integer)
                                                          )
                                                  )
                                      )
                      ));
 }
Ejemplo n.º 27
0
        public static CreateIndexDescriptor CreateIndex(string indexName)
        {
            CreateIndexDescriptor d = new CreateIndexDescriptor(indexName);

            d.Settings(
                y => y.NumberOfShards(3)
                )
            .Mappings(ms =>
                      ms.Map <NuGetSearchMain>(m =>
                                               m.Properties(p => p
                                                            .Text(t => t
                                                                  .Name(n => n.Name)
                                                                  .Fields(ff => ff
                                                                          .Keyword(k => k
                                                                                   .Name("keyword")
                                                                                   .IgnoreAbove(256)
                                                                                   )
                                                                          )
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.NameSplit)
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.NameSplitCamel)
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.Authors)
                                                                  .Fields(ff => ff
                                                                          .Keyword(k => k
                                                                                   .Name("keyword")
                                                                                   .IgnoreAbove(256)
                                                                                   )
                                                                          )
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.Description)
                                                                  .Fields(ff => ff
                                                                          .Text(tt => tt
                                                                                .Name("stop")
                                                                                .Analyzer("stop")
                                                                                )
                                                                          )
                                                                  )

                                                            .Text(t => t
                                                                  .Name(n => n.IconUrl)
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.ProjectUrl)
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.ReleaseNotes)
                                                                  .Fields(ff => ff
                                                                          .Text(tt => tt
                                                                                .Name("stop")
                                                                                .Analyzer("stop")
                                                                                )
                                                                          )
                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.Tags)

                                                                  )
                                                            .Text(t => t
                                                                  .Name(n => n.Title)
                                                                  .Fields(ff => ff
                                                                          .Text(tt => tt
                                                                                .Name("stop")
                                                                                .Analyzer("stop")
                                                                                )
                                                                          )
                                                                  )

                                                            .Date(dd => dd
                                                                  .Name(n => n.CommitTimeStamp)
                                                                  )

                                                            .Object <NuGetSearchMainDependencyGroup>(o => o
                                                                                                     .Name(n => n.DependencyGroups)
                                                                                                     .Properties(pp => pp
                                                                                                                 .Text(tt => tt
                                                                                                                       .Name(nnn => nnn.TargetFramework)
                                                                                                                       .Fields(ff => ff
                                                                                                                               .Keyword(kk => kk
                                                                                                                                        .Name("keyword")
                                                                                                                                        .IgnoreAbove(256)
                                                                                                                                        )
                                                                                                                               )
                                                                                                                       )
                                                                                                                 .Object <NuGetSearchMainDependency>(o2 => o2
                                                                                                                                                     .Name(nnnn => nnnn.Dependencies)
                                                                                                                                                     .Properties(pppp => pppp
                                                                                                                                                                 .Text(tttt => tttt
                                                                                                                                                                       .Name(nnnnn => nnnnn.Name)
                                                                                                                                                                       .Fields(fffff => fffff
                                                                                                                                                                               .Keyword(kkkkk => kkkkk
                                                                                                                                                                                        .Name("keyword")
                                                                                                                                                                                        .IgnoreAbove(256)
                                                                                                                                                                                        )
                                                                                                                                                                               )
                                                                                                                                                                       )
                                                                                                                                                                 .Text(tttt => tttt
                                                                                                                                                                       .Name(nnnnn => nnnnn.VersionRange)
                                                                                                                                                                       )
                                                                                                                                                                 )
                                                                                                                                                     )
                                                                                                                 )
                                                                                                     )
                                                            )
                                               )
                      );
            return(d);
        }