【问题标题】:Auto mapping in ElasticSearch NEST client using underscore使用下划线在 ElasticSearch NEST 客户端中自动映射
【发布时间】:2017-07-24 16:22:52
【问题描述】:

ElasticSearch 建议在字段名称中使用下划线。 我正在使用 Nest 客户端,我有以下类型:

public class Employee
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Nest 客户端提供了一种称为自动映射的功能,可以从 POCO 的属性中自动推断出正确的映射。如果使用此功能,我将得到:

"employee": {
    "properties": {
        "firstName": {
            "fields": {
                "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                }
            },
            "type": "text"
        },
        "lastName": {
            "fields": {
                "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                }
            },
            "type": "text"
        },
    }
}

但字段不符合命名约定。使用属性定义自己的映射还有另一个功能。但我不想为每个字段手动指定它。那么有没有可能配置客户端默认使用下划线来组合单词呢?

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    您可以通过DefaultFieldNameInferrer(Func<string, string>) on ConnectionSettings将默认使用驼峰式大小写的字段名推断改为使用蛇形大小写

    【讨论】:

      猜你喜欢
      • 2016-08-27
      • 2012-09-23
      • 2017-12-22
      • 2015-02-19
      • 2018-02-18
      • 1970-01-01
      • 2020-12-22
      • 2015-07-21
      • 1970-01-01
      相关资源
      最近更新 更多