Example #1
0
        public virtual CreateIndexDescriptor Map(CreateIndexDescriptor descriptor)
        {
            Func <Func <TypeMappingDescriptor <T>, ITypeMapping>, CreateIndexDescriptor> seed = f =>
            {
                descriptor = descriptor.Mappings(m => m.Map <T>(f));
                return(descriptor);
            };

            var res = this.Mappers.Aggregate(seed, (x, next) =>
            {
                var returnRes = new Func <Func <TypeMappingDescriptor <T>, ITypeMapping>, CreateIndexDescriptor>
                                (
                    pr =>
                {
                    x(next.MapProperty(pr));

                    return(descriptor);
                });
                return(returnRes);
            });

            var desc = res(new Func <TypeMappingDescriptor <T>, ITypeMapping>(q => null));

            return(desc);
        }
Example #2
0
        private void CreateTracingIndexExecute(string index)
        {
            _logger.LogInformation($"Not exists index {index}.");

            var tracingIndex = new CreateIndexDescriptor(index);

            tracingIndex.Mappings(x =>
                                  x.Map <Span>(m => m
                                               .AutoMap()
                                               .Properties(p => p.Keyword(t => t.Name(n => n.TraceId)))
                                               .Properties(p => p.Keyword(t => t.Name(n => n.SpanId)))
                                               .Properties(p => p.Nested <Tag>(n => n.Name(name => name.Tags).AutoMap()))));

            var response = _elasticClient.CreateIndex(tracingIndex);

            if (response.IsValid)
            {
                _logger.LogInformation($"Create index {index} success.");
            }
            else
            {
                var exception = new InvalidOperationException($"Create index {index} error : {response.ServerError}");
                _logger.LogError(exception, exception.Message);
                throw exception;
            }
        }
 public virtual ICreateIndexRequest DescribeIndex(CreateIndexDescriptor createIndexDescriptor)
 {
     return(createIndexDescriptor.Mappings(m => m
                                           .Map <TUser>(mm => mm
                                                        .AutoMap()
                                                        .AllField(af => af
                                                                  .Enabled(false)))));
 }
 public override ICreateIndexRequest DescribeIndex(CreateIndexDescriptor createIndexDescriptor)
 {
     return(createIndexDescriptor.Mappings(m => m
                                           .Map <ExtendedUser>(mm => mm
                                                               .AutoMap()
                                                               .Dynamic(true)
                                                               .AllField(af => af
                                                                         .Enabled(false)))));
 }
        private void CreateDocument(ParentTestClass document, IndexName index, ElasticClient client)
        {
            //var index = new IndexName { Name = "TestName", Type = typeof(ParentTestClass) };
            var descriptor = new CreateIndexDescriptor(index);
            var t          = new Test();

            var t1 = new Test1();

            Func <Func <TypeMappingDescriptor <ParentTestClass>, ITypeMapping>, CreateIndexDescriptor> seed = f =>
            {
                descriptor = descriptor.Mappings(m => m.Map <ParentTestClass>(f));
                return(descriptor);
            };

            var list = new List <Test> {
                t, t1
            };

            var res = list.Aggregate(seed, (x, next) =>
            {
                //throw new NotImplementedException();

                var returnRes = new Func <Func <TypeMappingDescriptor <ParentTestClass>, ITypeMapping>, CreateIndexDescriptor>
                                (
                    pr =>
                {
                    x(next.F(pr));

                    return(descriptor);

                    throw new NotImplementedException();
                });
                return(returnRes);
            });

            var ex = res(new Func <TypeMappingDescriptor <ParentTestClass>, ITypeMapping>(q => null));

            client.CreateIndex(descriptor);
            var documentType = document.GetType();
            //var client = this._clientFactory.GetClient();

            var documentPath = new DocumentPath <ParentTestClass>(document);

            //var index = this.GetIndex(document, client);

            documentPath.Type(documentType);
            documentPath.Index(index);

            var createRequest = new CreateRequest <ParentTestClass>(documentPath);

            var response = client.Create(createRequest);
        }
Example #6
0
        private void CreateServiceIndexExecute(string index)
        {
            _logger.LogInformation($"Not exists index {index}.");

            var serviceIndex = new CreateIndexDescriptor(index);

            serviceIndex.Mappings(x =>
                                  x.Map <Service>(m => m
                                                  .Properties(p => p.Keyword(k => k.Name(n => n.Name)))));

            var response = _elasticClient.CreateIndex(serviceIndex);

            if (response.IsValid)
            {
                _logger.LogInformation($"Create index {index} success.");
            }
            else
            {
                var exception = new InvalidOperationException($"Create index {index} error : {response.ServerError}");
                _logger.LogError(exception, exception.Message);
                throw exception;
            }
        }
Example #7
0
 public override CreateIndexDescriptor Map(CreateIndexDescriptor descriptor)
 {
     descriptor.Mappings(m => m.Map <ParentTestClass>(x =>
                                                      x.Properties(p => p.Nested <ChildClass>(nested => nested.Name(parent => parent.Children)))));
     return(descriptor);
 }
 protected override ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor create) => create
 .Mappings(m => m
           .Map <Project>(mm => mm
                          .AutoMap()
                          )
           );
        partial void MapIndexModels(CreateIndexDescriptor indexer)
        {
            indexer.Mappings(mp => mp.Map <sdk.Account>(DocumentNames.Account, p => p
                                                        .AutoMap()
                                                        .Properties(props => props
                                                                    .String(s => s
                                                                            .Name(n => n.account_id)
                                                                            .Index(FieldIndexOption.NotAnalyzed)
                                                                            ).String(m => m
                                                                                     .Name(t => t.email)
                                                                                     .Fields(f => f
                                                                                             .String(s => s.Name(n => n.email)
                                                                                                     .Index(FieldIndexOption.Analyzed))
                                                                                             .String(s => s
                                                                                                     .Name(n => n.email.Suffix("sort"))
                                                                                                     .Analyzer("case_insensitive"))

                                                                                             )
                                                                                     ).String(m => m
                                                                                              .Name(t => t.first_name)
                                                                                              .Fields(f => f
                                                                                                      .String(s => s.Name(n => n.first_name)
                                                                                                              .Index(FieldIndexOption.Analyzed))
                                                                                                      .String(s => s
                                                                                                              .Name(n => n.first_name.Suffix("sort"))
                                                                                                              .Analyzer("case_insensitive"))

                                                                                                      )
                                                                                              ).String(m => m
                                                                                                       .Name(t => t.last_name)
                                                                                                       .Fields(f => f
                                                                                                               .String(s => s.Name(n => n.last_name)
                                                                                                                       .Index(FieldIndexOption.Analyzed))
                                                                                                               .String(s => s
                                                                                                                       .Name(n => n.last_name.Suffix("sort"))
                                                                                                                       .Analyzer("case_insensitive"))

                                                                                                               )
                                                                                                       ).String(m => m
                                                                                                                .Name(t => t.last_login_utc)
                                                                                                                .Fields(f => f
                                                                                                                        .String(s => s.Name(n => n.last_login_utc)
                                                                                                                                .Index(FieldIndexOption.Analyzed))
                                                                                                                        .String(s => s
                                                                                                                                .Name(n => n.last_login_utc.Suffix("sort"))
                                                                                                                                .Analyzer("case_insensitive"))

                                                                                                                        )
                                                                                                                ).String(m => m
                                                                                                                         .Name(t => t.last_login_platform)
                                                                                                                         .Fields(f => f
                                                                                                                                 .String(s => s.Name(n => n.last_login_platform)
                                                                                                                                         .Index(FieldIndexOption.Analyzed))
                                                                                                                                 .String(s => s
                                                                                                                                         .Name(n => n.last_login_platform.Suffix("sort"))
                                                                                                                                         .Analyzer("case_insensitive"))

                                                                                                                                 )
                                                                                                                         )
                                                                    )
                                                        ));
        }