예제 #1
0
        /// <summary>
        /// NEST Backwards compatibility
        /// </summary>
        public static MappingsDescriptor AddMapping <T>(this MappingsDescriptor mapping, TypeName typeName, Func <TypeMappingDescriptor <T>, ITypeMapping> map)
            where T : class
        {
            var item = mapping.Map(typeName, map);

            return(mapping);
        }
 protected override IPromise <IMappings> ApplyAggregateMappingsOnIndex(MappingsDescriptor md)
 {
     return(md.Map <Favorites>(tm => tm
                               .Properties(prop => prop
                                           .Keyword(x => x.Name(nameof(Version)))
                                           .Date(x => x.Name(nameof(AggregateSnapshot <Favorites, FavoritesId> .RequestTimestamp)))
                                           .Keyword(x => x.Name(n => n.ObjectType))
                                           .Keyword(x => x.Name(n => n.FavoritedBy)))));
 }
        public static async Task <ICreateIndexResponse> CreateIndexAsync(
            this IElasticClient client,
            string indexName,
            IIndexSettings indexSettings = null,
            MappingsDescriptor mappings  = null)
        {
            if (string.IsNullOrEmpty(indexName))
            {
                throw new ArgumentNullException(nameof(indexName));
            }

            return(await CreateIndexAsync(client, indexSettings, mappings, indexName));
        }
        public virtual CreateIndexDescriptor ConfigureIndex(CreateIndexDescriptor idx)
        {
            var aliases  = new AliasesDescriptor();
            var mappings = new MappingsDescriptor();

            foreach (var t in IndexTypes)
            {
                aliases  = t.ConfigureIndexAliases(aliases);
                mappings = t.ConfigureIndexMappings(mappings);
            }

            return(idx.Aliases(a => aliases).Mappings(m => mappings));
        }
 protected override IPromise <IMappings> ApplyAggregateMappingsOnIndex(MappingsDescriptor md)
 {
     return(md.Map <PublicScheme>(tm => tm
                                  .Properties(prop => prop
                                              .Keyword(x => x.Name(nameof(Version)))
                                              .Date(x => x.Name(nameof(AggregateSnapshot <PublicScheme, PublicSchemeId> .RequestTimestamp)))
                                              .Keyword(x => x.Name(n => n.PublisherId))
                                              .Keyword(x => x.Name(n => n.Description))
                                              .Object <ColorScheme>(cs => cs
                                                                    .Name(x => x.ColorScheme)
                                                                    .AutoMap()
                                                                    .Properties(eProp => eProp
                                                                                .Keyword(x => x.Name(n => n.colorSchemeId))
                                                                                .Keyword(x => x.Name(n => n.colorSchemeName)))))));
 }
        public static void TestPage_Type_Mapping_Should_Create_Index_And_Return_IsValid()
        {
            var elasticClient = new ElasticClient(new Uri("http://localhost:9200"));
            var helper = new TypeScanIndexableTypeMapperResolver();
            var indexableTypeMappers = helper.GetAll().ToList();

            var typeMapper = indexableTypeMappers.First();
            var typeMapping = typeMapper.CreateTypeMapping(new CultureInfo("en"));
            var typeName = typeMapper.TypeName;

            var mappingsDescriptor = new MappingsDescriptor();
            mappingsDescriptor.Map<IIndexablePageData>(typeName, x => typeMapping);
            var createIndexResponse = elasticClient.CreateIndex("site_en_1", x => x.Mappings(m => mappingsDescriptor));

            Assert.Equal(true, createIndexResponse.IsValid);
            Assert.Equal(true, createIndexResponse.Acknowledged);
        }
        private static async Task <ICreateIndexResponse> CreateIndexAsync(
            IElasticClient client,
            IIndexSettings indexSettings,
            MappingsDescriptor mappings,
            string indexName)
        {
            indexSettings = indexSettings ?? new IndexSettings();
            mappings      = mappings ?? new MappingsDescriptor();

            var response = await client.CreateIndexAsync(
                indexName,
                createDescriptor => createDescriptor
                .Settings(settingDescriptor => settingDescriptor
                          .NumberOfShards(indexSettings.NumberOfShards)
                          .FileSystemStorageImplementation(
                              indexSettings.FileSystemStorageImplementation))
                .Mappings(mappingsDescriptor => mappings));

            return(response);
        }
예제 #8
0
#pragma warning restore 618

#pragma warning disable 618
        public static ITypeMapping ProjectMappings(MappingsDescriptor map) => map
        .Map <Project>(ProjectTypeMappings);
예제 #9
0
 protected abstract IPromise <IMappings> ApplyAggregateMappingsOnIndex(MappingsDescriptor md);
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task Reindex(bool refreshAllIndex, string refreshIndex, string companyId)
        {
            var userName = _httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(s => s.Type == "userName")?.Value;

            if (userName == "*****@*****.**")
            {
                if (refreshAllIndex)
                {
                    foreach (var item in GetTypes())
                    {
                        await DeleteIndexES(item.Key);
                    }
                }

                if (!string.IsNullOrEmpty(refreshIndex))
                {
                    await DeleteIndexES(refreshIndex);
                }

                var analyzers = new AnalysisDescriptor().Analyzers(aa => aa
                                                                   .Custom("folding", sa => sa.Tokenizer("standard").Filters("lowercase", "asciifolding").CharFilters("html_strip"))
                                                                   .Custom("sortable", sa => sa.Tokenizer("keyword").Filters("lowercase", "asciifolding"))
                                                                   .Custom("uax", sa => sa.Tokenizer("uax_url_email").Filters("lowercase", "stop"))
                                                                   );

                var mappingDescriptor = new MappingsDescriptor();

                foreach (var item in GetTypes())
                {
                    if (!_esClient.IndexExists(item.Key).Exists)
                    {
                        switch (item.Key)
                        {
                        case "activity_history_leads":
                            mappingDescriptor = mappingDescriptor.Map <ActivityHistoryLead>(mm => mm
                                                                                            .Properties(p => p
                                                                                                        .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                        )
                                                                                            );
                            break;

                        case "chat_leads":
                            mappingDescriptor = mappingDescriptor.Map <ChatLead>(mm => mm
                                                                                 .Properties(p => p
                                                                                             .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                             )
                                                                                 );
                            break;

                        case "companies":
                            mappingDescriptor = mappingDescriptor.Map <Company>(mm => mm
                                                                                .Properties(p => p
                                                                                            .Text(t => t.Name(n => n.CompanyName).Analyzer("folding").SearchAnalyzer("folding"))
                                                                                            .Text(t => t.Name(n => n.Email).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                            .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                            .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                            )
                                                                                );
                            break;

                        case "contact_leads":
                            mappingDescriptor = mappingDescriptor.Map <ContactLead>(mm => mm
                                                                                    .Properties(p => p
                                                                                                .Text(t => t.Name(n => n.Name).Analyzer("folding").SearchAnalyzer("folding"))
                                                                                                .Text(t => t.Name(n => n.Email).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                )
                                                                                    );
                            break;

                        case "common_data":
                            mappingDescriptor = mappingDescriptor.Map <CommonData>(mm => mm
                                                                                   .Properties(p => p
                                                                                               .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                               .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                               )
                                                                                   );
                            break;

                        case "leads":
                            mappingDescriptor = mappingDescriptor.Map <Lead>(mm => mm
                                                                             .Properties(p => p
                                                                                         .Text(t => t.Name(n => n.FullName).Analyzer("folding").SearchAnalyzer("folding"))
                                                                                         .Text(t => t.Name(n => n.Email).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                         .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                         .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                         )
                                                                             );
                            break;

                        case "product_categories":
                            mappingDescriptor = mappingDescriptor.Map <ProductCategory>(mm => mm
                                                                                        .Properties(p => p
                                                                                                    .Text(t => t.Name(n => n.Name).Analyzer("folding").SearchAnalyzer("folding"))
                                                                                                    .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                    .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                    )
                                                                                        );
                            break;

                        case "products":
                            mappingDescriptor = mappingDescriptor.Map <Product>(mm => mm
                                                                                .Properties(p => p
                                                                                            .Text(t => t.Name(n => n.Name).Analyzer("folding").SearchAnalyzer("folding"))
                                                                                            .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                            .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                            )
                                                                                );
                            break;

                        case "teams":
                            mappingDescriptor = mappingDescriptor.Map <Team>(mm => mm
                                                                             .Properties(p => p
                                                                                         .Text(t => t.Name(n => n.Name).Analyzer("folding").SearchAnalyzer("folding"))
                                                                                         .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                         .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                         )
                                                                             );
                            break;

                        case "team_users":
                            mappingDescriptor = mappingDescriptor.Map <TeamUsers>(mm => mm
                                                                                  .Properties(p => p
                                                                                              .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                              .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                              )
                                                                                  );
                            break;

                        case "access_rights":
                            mappingDescriptor = mappingDescriptor.Map <AccessRight>(mm => mm
                                                                                    .Properties(p => p
                                                                                                .Text(t => t.Name(n => n.CreatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                .Text(t => t.Name(n => n.UpdatedBy).Analyzer("uax").SearchAnalyzer("uax"))
                                                                                                )
                                                                                    );
                            break;
                        }
                        await _esClient.CreateIndexAsync(item.Key, c => c
                                                         .Settings(s => s.Analysis(a => analyzers))
                                                         .Mappings(m => mappingDescriptor
                                                                   )
                                                         );

                        await Migrate(item.Key, companyId);
                    }
                }
            }
        }
예제 #11
0
 public static IPromise <IMappings> UserAccountIndexMappings(MappingsDescriptor ms)
 {
     return(ms.Map <UserAccount>(m => m.AutoMap(-1)));
 }
예제 #12
0
 public static IPromise <IMappings> RepoSettingsIndexMappings(MappingsDescriptor ms)
 {
     return(ms.Map <RepoSettings>(m => m.AutoMap(-1)));
 }
예제 #13
0
 public static IPromise <IMappings> JobsIndexMappings(MappingsDescriptor ms)
 {
     return(ms.Map <JobInfo>(m => m.AutoMap(-1)));
 }
 protected override IPromise <IMappings> ApplyAggregateMappingsOnIndex(MappingsDescriptor md)
 {
     ApplyAggregateMappingsOnIndex_CallCount++;
     return(md);
 }
예제 #15
0
 public virtual MappingsDescriptor ConfigureIndexMappings(MappingsDescriptor mappings)
 {
     return(mappings.Map <T>(Name, BuildMapping));
 }
        protected virtual MappingsDescriptor CreateMappingsDescriptor(CultureInfo language)
        {
            var mappingsDescriptor = new MappingsDescriptor();

            foreach (var indexableTypeMapper in _indexableTypeMapperResolver.GetAll())
            {
                var typeMapping = indexableTypeMapper.CreateTypeMapping(language);
                mappingsDescriptor.Map<IIndexablePageData>(indexableTypeMapper.TypeName, x => typeMapping);
            }

            return mappingsDescriptor;
        }