elasticsearch - How to use multiple index analyzers in NEST? -


i have company type i've created. inside of company type have field called "summary". how can add multiple index analyzers field?

i briefly looked using yakaz plugin, doesn't appear can use nest.

the reasoning behind users search company names period in query, other times won't include period. i'd partial match using ngrams on both company name , without punctuation. i'm using stopwords filter remove punctuation.

properties of summary field(having multiple index analyzers throws error):

[elasticproperty(indexanalyzer = "partial_match", indexanalyzer = "partial_match_no_punctuation", searchanalyzer = "full_match")] public string summary { get; set; } 

mapping:

private static void createmapping(elasticclient client) {     var partialmatchnopunctuation = new customanalyzer     {         filter = new list<string> { "standard", "lowercase", "asciifolding", "punctuation_filter", "name_ngrams" },  //apply filters before ngram         tokenizer = "standard"     };     var partialmatch = new customanalyzer     {         filter = new list<string> { "standard", "lowercase", "asciifolding", "name_ngrams" },  //apply filters before ngram         tokenizer = "standard"     };      var fullmatch = new customanalyzer     {         filter = new list<string> { "standard", "lowercase", "asciifolding" },         tokenizer = "standard"     };      client.createindex(settings.default.indexname, c => c         .analysis(descriptor => descriptor             .tokenfilters(bases => bases                 .add("name_ngrams", new ngramtokenfilter                 {                     maxgram = 11,                     mingram = 3                 })                 .add("punctuation_filter", new stoptokenfilter                 {                     stopwords = new list<string> {"."}                 })                 )             .analyzers(bases => bases                 .add("partial_match", partialmatch)                 .add("partial_match_no_punctuation", partialmatchnopunctuation)                 .add("full_match", fullmatch))         )     ); } 

alternatively if there's way in single analyzer i'm open suggestions.

edit:

my class name "elasticsearchproject". i'd stored type called "project". believe attempt @ causing errors. when mapping type project, has partial match analyzer applied it.

this es property still applied class:

[elastictype(name = "project")] 

multi-field mapping:

.addmapping<elasticsearchproject>(m => m     .mapfromattributes()     .properties(project=>project         .multifield(mf=>mf             .name("project")             .fields(f=>f                 .number(s=>s.name(o=>o.id).index(nonstringindexoption.no))                 .string(s => s.name(o => o.summary).indexanalyzer("partial_match"))                 .string(s => s.name(o => o.summary).indexanalyzer("partial_match_no_punctuation"))             )))) 

first, answer question, cannot add multiple analyzers single field. however, can use multi field type map multiple versions of same field, , apply different analyzer each of them. checkout answer how accomplish nest.

in regards searching , without punctuation, if use same analyzer index , search analyzer, won`t matter because same analysis applied field during indexing applied users query.

example:

foo.bar indexed foobar.

if user searches either foo.bar or foobar, search analyzer transform foobar, , match found because field indexed foobar.

i think part of issue trying use full_match search analyzer, , partial_match_no_punctuation , partial_match index analyzer. try , reconcile them 1 (remove punctuation, ngrams), , use both search , index analyzers. if find still need multiple analyzers, multi field type mentioned above.

hope helps.

edit: per update, issue multi field mapping trying assign same name both fields. additionally, naming field "project", name of type, want name "summary" instead. also, don't want include id field part of summary multi field. try instead:

.addmapping<elasticsearchproject>(m => m .mapfromattributes() .properties(project => project     .multifield(mf => mf         .name(o => o.summary)         .fields(f => f             .string(s => s.name(o => o.summary).analyzer("partial_match"))             .string(s => s.name(o => o.summary.suffix("no_punctuation")).analyzer("partial_match_no_punctuation"))         ))))); 

this create 2 fields in mapping:

summary partial_match analyzer.

summary.no_puncuation partial_match_no_punctuation analyzer.


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 -