【问题标题】:Custom Analyzer - Attribute Based Mapping - Nest 2.X自定义分析器 - 基于属性的映射 - Nest 2.X
【发布时间】:2016-12-09 00:53:48
【问题描述】:

我想知道如何添加自定义分析器作为属性,这将允许我在弹性搜索嵌套客户端 2.x 中自动映射而不是手动映射

示例: 我有一个模型

公共类员工 {

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

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

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

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    您可以在创建索引时定义分析器。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多