Set index.query.default_field using NEST Client c#

2019-09-06 09:33发布

I need to set index.query.default_field while creating index.How can I do it using Nest client c#. Added my create index code.Where do I set default_field property?

 var fullNameFilters = new List<string> { "lowercase", "snowball" };
    client.CreateIndex("mydocs", c => c
          .Settings(st => st
                    .Analysis(anl => anl
                    .Analyzers(h => h
                        .Custom("full", ff => ff
                             .Filters(fullNameFilters)
                             .Tokenizer("standard"))
                        )
                        .TokenFilters(ba => ba
                            .Snowball("snowball", sn => sn
                                .Language(SnowballLanguage.English)))                    
                        ))
                     .Mappings(mp => mp
                     .Map<IndexDocument>(ms => ms
                     .AutoMap()
                     .Properties(ps => ps
                         .Nested<Attachment>(n => n
                             .Name(sc => sc.File)
                         .AutoMap()
                         ))
                    .Properties(at => at
                    .Attachment(a => a.Name(o => o.File)
                    .FileField(fl=>fl.Analyzer("full"))
                    .TitleField(t => t.Name(x => x.Title)
                    .Analyzer("full")
                    .TermVector(TermVectorOption.WithPositionsOffsets)
                    )))

                    ))                        
                    );

1条回答
唯我独甜
2楼-- · 2019-09-06 10:07

You can use Settings method when creating index:

var createIndexResponse =
    client.CreateIndex(indexName, c => c
        .Settings(s => s.Setting("index.query.default_field", "field"))
        .Mappings(m => m
            .Map<Document>(mp => mp.AutoMap())));

Hope it helps.

查看更多
登录 后发表回答