Reputation: 11
I would like to know the way to add a custom analyzer as an attribute which will allow me to automap instead of manual mapping in elastic search nest client 2.x
Example: I have a model
public class Employee {
[String]
public string FName {get; set;}
[String(Analyzer = "my_analyzer")]
public string EmployeeId { get; set; }
}
Where do I define my_analyzer so that it can be auto mapped?
Upvotes: 1
Views: 805
Reputation: 2205
You can define your analyzer when you're creating the index.
public void CreateIndex(string indexName)
{
// Define the analyzer
var customAnalyzer = new CustomAnalyzer();
customAnalyzer.Tokenizer = "my_tokenizer"; // add a tokenizer
customAnalyzer.Filter = new List<string>();
customAnalyzer.Filter.ToList().Add("lowercase"); // add some filters
// Add the analyzer to your index settings
var request = new CreateIndexRequest(indexName);
request.Settings.Analysis.Analyzers = new Analyzers();
request.Settings.Analysis.Analyzers.Add("my_analyzer", customAnalyzer);
// Create the index
ElasticClient nestClient = new ElasticClient();
var indexResponse = nestClient.CreateIndex(request);
}
Upvotes: 0