Elasticsearch Nest C# - ElasticProperty Analyzer导致动态映射

时间:2015-01-30 13:34:30

标签: c# elasticsearch mapping nest

我使用ElasticProperty属性来定义我的索引类型映射。这有效:

[ElasticProperty(Boost = 2)]
public string Title { get; set; }
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string ActivityType { get; set; }

我创建了索引,一切看起来都不错(我只是复制受影响的道具):

        "properties": {
           "activityType": {
              "type": "string",
              "index": "not_analyzed"
           },
           "title": {
              "type": "string",
              "boost": 2
           }
        }

但是,当我删除映射时,更改分析器并重新索引观察会发生什么:

[ElasticProperty(Boost = 2, Analyzer = "keyword")]
public string Title { get; set; }
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string ActivityType { get; set; }

结果:

       "properties": {
           "activityType": {
              "type": "string"
           },
           "title": {
              "type": "string"
           }
       }

有人可以解释这里发生了什么吗?似乎添加Analyzer参数会强制动态生成映射。为什么呢?

1 个答案:

答案 0 :(得分:1)

确保在您的应用程序启动时调用以下内容:

private readonly IElasticClient _client;
//initialize _client
_client.Map<YourTypeHere>(m => m.MapFromAttributes());

该代码将应用您拥有的任何新映射。