尝试映射附件属性,如下所示:
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
答案 0 :(得分:0)
在this issue修复后,此映射有效:
[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; }
}