我想知道添加自定义分析器作为属性的方法,这将允许我在弹性搜索嵌套客户端2.x中自动而不是手动映射
实施例: 我有一个模特
公共类员工 {
[String]
public string FName {get; set;}
[String(Analyzer = "my_analyzer")]
public string EmployeeId { get; set; }
}
我在哪里定义my_analyzer以便可以自动映射?
答案 0 :(得分:0)
您可以在创建索引时定义分析器。
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);
}