Skip to content

Commit 5f8bf94

Browse files
committed
added title, and ability for any metadatafield to be specified on the attachment mapping fixes #330
1 parent 89894fc commit 5f8bf94

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

Diff for: src/Nest.Tests.Unit/Core/Map/Properties/AttachmentProperty.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"elasticsearchprojects": {
33
"properties": {
44
"myAttachment": {
@@ -9,6 +9,16 @@
99
"store": "yes",
1010
"index": "not_analyzed"
1111
},
12+
"title": {
13+
"type": "string",
14+
"store": "no",
15+
"index": "not_analyzed"
16+
},
17+
"contents": {
18+
"type": "string",
19+
"store": "no",
20+
"index": "not_analyzed"
21+
},
1222
"author": {
1323
"type": "string",
1424
"store": "no",

Diff for: src/Nest.Tests.Unit/Core/Map/Properties/PropertiesTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public void AttachmentProperty()
115115
.Attachment(s => s
116116
.Name(p => p.MyAttachment)
117117
.FileField(fs => fs.Index(FieldIndexOption.not_analyzed).Store())
118+
.TitleField(fs => fs.Index(FieldIndexOption.not_analyzed).Store(false))
119+
.MetadataField("contents", fs => fs.Index(FieldIndexOption.not_analyzed).Store(false))
118120
.AuthorField(fs => fs.Index(FieldIndexOption.analyzed).Store(false))
119121
.DateField(fs => fs.Store(false).IncludeInAll())
120122
)

Diff for: src/Nest/Domain/Mapping/Descriptors/AttachmentMappingDescriptor.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,30 @@ public AttachmentMappingDescriptor<T> AuthorField(Func<StringMappingDescriptor<T
3434
{
3535
stringMapper.ThrowIfNull("stringMapper");
3636
var d = stringMapper(new StringMappingDescriptor<T>());
37-
d.ThrowIfNull("stringMapper return value");
37+
d.ThrowIfNull("attachment author field mapping");
3838

3939
this._Mapping.Fields["author"] = d._Mapping;
4040
return this;
4141
}
42+
public AttachmentMappingDescriptor<T> TitleField(Func<StringMappingDescriptor<T>, StringMappingDescriptor<T>> stringMapper)
43+
{
44+
stringMapper.ThrowIfNull("stringMapper");
45+
var d = stringMapper(new StringMappingDescriptor<T>());
46+
d.ThrowIfNull("attachment title field");
47+
48+
this._Mapping.Fields["title"] = d._Mapping;
49+
return this;
50+
}
51+
public AttachmentMappingDescriptor<T> MetadataField(string metadataFieldName, Func<StringMappingDescriptor<T>, StringMappingDescriptor<T>> stringMapper)
52+
{
53+
metadataFieldName.ThrowIfNullOrEmpty("metadataFieldName");
54+
stringMapper.ThrowIfNull("stringMapper");
55+
var d = stringMapper(new StringMappingDescriptor<T>());
56+
d.ThrowIfNull("attachment metadata field");
57+
58+
this._Mapping.Fields[metadataFieldName] = d._Mapping;
59+
return this;
60+
}
4261
public AttachmentMappingDescriptor<T> DateField(Func<DateMappingDescriptor<T>, DateMappingDescriptor<T>> dateMapper)
4362
{
4463
dateMapper.ThrowIfNull("stringMapper");

0 commit comments

Comments
 (0)