附件字段未在 Nest 2 中正确映射

本文关键字:映射 Nest 字段 | 更新日期: 2023-09-27 18:34:36

尝试像这样映射附件属性:

client.Map<Case>(m => m.UpdateAllTypes());

使用此类和映射定义:

[ElasticsearchType(Name = "cases")]
public class Case
{
    public string Author { get; set; }
    public string CaseName { get; set; }
    [Attachment(Store = true)]
    public Attachment File { get; set; }
}

public class Attachment
{
    [String(Name = "_content")]
    public string Content { get; set; }
    [String(Name = "_content_type")]
    public string ContentType { get; set; }
    [String(Name = "_name")]
    public string Name { get; set; }
}

导致此生成的映射

"mappings": {
  "cases": {
    "properties": {
      "author": {
        "type": "string"
      },
      "case_name": {
        "type": "string"
      },
      "file": {
        "properties": {
          "_content": {
            "type": "string"
          },
          "_content_type": {
            "type": "string"
          },
          "_name": {
            "type": "string"
          }
        }
      }
    }
  }

是的,文件属性定义"type": "attachment"缺失。

使用 Elasticsearch 2.2, Nest 2.0.2, Mono/.Net 4.5

附件字段未在 Nest 2 中正确映射

此问题修复后,此映射有效:

[ElasticsearchType(Name = "cases")]
public class Case
{
    public Case()
    {
    }
    [String(Name = "case_name")]
    public string CaseName { get; set; }
    [String(Name = "md5")]
    public string Md5 { get; set; }
    [Attachment(Name="file")]
    public Attachment File { get; set; }
}

public class Attachment
{
    public Attachment()
    {
    }
    [String(Name = "_author")]
    public string Author { get; set; }
    [String(Name = "_content_lenght")]
    public long ContentLength { get; set; }
    [String(Name = "_content_type")]
    public string ContentType { get; set; }
    [Date(Name = "_date")]
    public DateTime Date { get; set; }
    [String(Name = "_keywords")]
    public string Keywords { get; set; }
    [String(Name = "_language")]
    public string Language { get; set; }
    [String(Name = "_name")]
    public string Name { get; set; }
    [String(Name = "_title")]
    public string Title { get; set; }
    [String(Name = "_content")]
    public string Content { get; set; }
}