2016-12-02 77 views
0

我想知道添加自定义分析仪作为一个属性,这将让我自动映射,而不是弹性搜索巢2.x的客户端手动映射的方式自定义分析 - 基于属性的映射 - 鸟巢2.X

例子: 我有一个模型

公共类员工 {

[String] 
    public string FName {get; set;} 

    [String(Analyzer = "my_analyzer")] 
    public string EmployeeId { get; set; } 
} 

在哪里定义my_analyzer,以便它可以自动映射?

回答

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); 
}