NEST 7忽略属性映射,但仍在_source中可用

问题描述 投票:0回答:1

如何使用NEST 7客户端转换此映射。我正在尝试将启用的设置设置为false。这将导致Elasticsearch完全跳过对字段内容的解析,但仍可从_source使用它。

PUT my_index
{
  "mappings": {
    "properties": {
      "user_id": {
        "type":  "keyword"
      },
      "last_updated": {
        "type": "date"
      },
      "session_data": { 
        "type": "object",
        "enabled": false
      }
    }
  }
}
nest
1个回答
1
投票

一种方法是使用attribute mapping

await client.Indices.CreateAsync("documents", c => c
    .Map<Document>(m => m.AutoMap()));

public class Document
{
    public string Id { get; set; }
    [Object(Enabled = false)]
    public object Data { get; set; }
}

另一种是使用fluent mapping

await client.Indices.CreateAsync("documents", c => c
    .Map<Document>(m => m
        .Properties(p => p.Object<object>(o => o.Name(n => n.Data).Enabled(false)))));

您可以在docs中找到更多内容。

希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.