I have a Company type I've created. Inside of that Company type I have a field called "Summary". How can I add multiple index analyzers to this field?
I briefly looked into using the Yakaz plugin, but it doesn't appear I can use that with NEST.
The reasoning behind this is that sometimes users will search for company names with a period in their query, other times they won't include the period. I'd like to do a partial match using ngrams on both the company name with and without punctuation. I'm currently using a stopwords filter to remove punctuation.
Properties of the Summary field(Having multiple Index analyzers throws an 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 all filters before ngram
Tokenizer = "standard"
};
var partialMatch = new CustomAnalyzer
{
Filter = new List<string> { "standard", "lowercase", "asciifolding", "name_ngrams" }, //Apply all 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 a way to do this in a single analyzer I'm open to suggestions.
EDIT:
My class name is "ElasticSearchProject". I'd like it to be stored as a type called "Project". I believe my attempt at this is what is causing the errors. When I get the mapping for type Project, it only has the partial match analyzer applied to it.
This is the only ES property still applied to my 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"))
))))