c# - NEST - Index individual fields -


i'm transitioning elasticsearch on website , using nest c# .net interface.

in writing code index content, can't figure out how map fields individually. suppose have following:

var person = new person {     id = "1",     firstname = "martijn",     lastname = "laarman",     email = "martijn@gmail.com",     posts = "50",     yearsofexperience = "26"  }; 

rather indexing entire dataset using:

var index = client.index(person); 

i want index firstname , lastname can searched upon, don't need other fields in index (other id) because take space. can me code map these fields individually?

you should add mapping when create index initially. 1 way can using nest attributes on class this:

public class person {     public string id { get; set; }      public string firstname { get; set; }      public string lastname { get; set; }      [elasticproperty(store=false, index=fieldindexoption.not_analyzed)]     public string email { get; set; }      [elasticproperty(store = false, index = fieldindexoption.not_analyzed)]     public string posts { get; set; }      [elasticproperty(store = false, index = fieldindexoption.not_analyzed)]     public string yearsofexperience { get; set; } } 

then create index this:

client.createindex("person", c => c.addmapping<person>(m => m.mapfromattributes())); 

instead of using attributes, explicitly map each field:

client.createindex("person", c => c.addmapping<person>(m => m     .mapfromattributes()     .properties(props => props         .string(s => s.name(p => p.email).index(fieldindexoption.not_analyzed).store(false))         .string(s => s.name(p => p.posts).index(fieldindexoption.not_analyzed).store(false))         .string(s => s.name(p => p.yearsofexperience).index(fieldindexoption.not_analyzed).store(false))))); 

check out nest documentation more info, create index , put mapping sections.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -