Skip to content

Commit 8d1c8be

Browse files
committed
Update descriptor's with Fields()/Path()
1 parent 600669f commit 8d1c8be

File tree

6 files changed

+112
-9
lines changed

6 files changed

+112
-9
lines changed

src/Nest/Domain/Mapping/Descriptors/AttachmentMappingDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Nest
55
{
6-
public class AttachmentMappingDescriptor<T>
6+
public class AttachmentMappingDescriptor<T> where T : class
77
{
88
internal AttachmentMapping _Mapping = new AttachmentMapping();
99

src/Nest/Domain/Mapping/Descriptors/BooleanMappingDescriptor.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Nest
66
{
7-
public class BooleanMappingDescriptor<T>
7+
public class BooleanMappingDescriptor<T> where T : class
88
{
99
internal BooleanMapping _Mapping = new BooleanMapping();
1010

@@ -63,5 +63,26 @@ public BooleanMappingDescriptor<T> CopyTo(params Expression<Func<T, object>>[] o
6363
this._Mapping.CopyTo = objectPaths.Select(e => (PropertyPathMarker)e);
6464
return this;
6565
}
66+
67+
public BooleanMappingDescriptor<T> Path(MultiFieldMappingPath path)
68+
{
69+
this._Mapping.Path = path.Value;
70+
return this;
71+
}
72+
73+
public BooleanMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, CorePropertiesDescriptor<T>> fieldSelector)
74+
{
75+
fieldSelector.ThrowIfNull("fieldSelector");
76+
var properties = fieldSelector(new CorePropertiesDescriptor<T>());
77+
foreach (var p in properties.Properties)
78+
{
79+
var value = p.Value as IElasticCoreType;
80+
if (value == null)
81+
continue;
82+
83+
_Mapping.Fields[p.Key] = value;
84+
}
85+
return this;
86+
}
6687
}
6788
}

src/Nest/Domain/Mapping/Descriptors/DateMappingDescriptor.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Nest
55
{
6-
public class DateMappingDescriptor<T>
6+
public class DateMappingDescriptor<T> where T : class
77
{
88
internal DateMapping _Mapping = new DateMapping();
99

@@ -68,5 +68,25 @@ public DateMappingDescriptor<T> IgnoreMalformed(bool ignoreMalformed = true)
6868
return this;
6969
}
7070

71+
public DateMappingDescriptor<T> Path(MultiFieldMappingPath path)
72+
{
73+
this._Mapping.Path = path.Value;
74+
return this;
75+
}
76+
77+
public DateMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, CorePropertiesDescriptor<T>> fieldSelector)
78+
{
79+
fieldSelector.ThrowIfNull("fieldSelector");
80+
var properties = fieldSelector(new CorePropertiesDescriptor<T>());
81+
foreach (var p in properties.Properties)
82+
{
83+
var value = p.Value as IElasticCoreType;
84+
if (value == null)
85+
continue;
86+
87+
_Mapping.Fields[p.Key] = value;
88+
}
89+
return this;
90+
}
7191
}
7292
}

src/Nest/Domain/Mapping/Descriptors/GenericMappingDescriptor.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Nest
55
{
6-
public class GenericMappingDescriptor<T>
6+
public class GenericMappingDescriptor<T> where T : class
77
{
88
internal GenericMapping _Mapping = new GenericMapping();
99

@@ -75,5 +75,26 @@ public GenericMappingDescriptor<T> IncludeInAll(bool includeInAll = true)
7575
this._Mapping.IncludeInAll = includeInAll;
7676
return this;
7777
}
78+
79+
public GenericMappingDescriptor<T> Path(MultiFieldMappingPath path)
80+
{
81+
this._Mapping.Path = path.Value;
82+
return this;
83+
}
84+
85+
public GenericMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, CorePropertiesDescriptor<T>> fieldSelector)
86+
{
87+
fieldSelector.ThrowIfNull("fieldSelector");
88+
var properties = fieldSelector(new CorePropertiesDescriptor<T>());
89+
foreach (var p in properties.Properties)
90+
{
91+
var value = p.Value as IElasticCoreType;
92+
if (value == null)
93+
continue;
94+
95+
_Mapping.Fields[p.Key] = value;
96+
}
97+
return this;
98+
}
7899
}
79100
}

src/Nest/Domain/Mapping/Descriptors/NumberMappingDescriptor.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
using System.Linq.Expressions;
33

44
namespace Nest
5-
{
6-
public class NumberMappingDescriptor<T>
5+
{
6+
public class NumberMappingDescriptor<T> where T : class
77
{
88
internal NumberMapping _Mapping = new NumberMapping();
99

@@ -79,7 +79,27 @@ public NumberMappingDescriptor<T> Coerce(bool coerce = true)
7979
{
8080
this._Mapping.Coerce = coerce;
8181
return this;
82+
}
83+
84+
public NumberMappingDescriptor<T> Path(MultiFieldMappingPath path)
85+
{
86+
this._Mapping.Path = path.Value;
87+
return this;
88+
}
89+
90+
public NumberMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, CorePropertiesDescriptor<T>> fieldSelector)
91+
{
92+
fieldSelector.ThrowIfNull("fieldSelector");
93+
var properties = fieldSelector(new CorePropertiesDescriptor<T>());
94+
foreach (var p in properties.Properties)
95+
{
96+
var value = p.Value as IElasticCoreType;
97+
if (value == null)
98+
continue;
99+
100+
_Mapping.Fields[p.Key] = value;
101+
}
102+
return this;
82103
}
83-
84104
}
85105
}

src/Nest/Domain/Mapping/Descriptors/StringMappingDescriptor.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using System.Linq.Expressions;
44

55
namespace Nest
6-
{
7-
public class StringMappingDescriptor<T>
6+
{
7+
public class StringMappingDescriptor<T> where T : class
88
{
99
internal StringMapping _Mapping = new StringMapping();
1010

@@ -118,6 +118,27 @@ public StringMappingDescriptor<T> CopyTo(params Expression<Func<T, object>>[] ob
118118
{
119119
this._Mapping.CopyTo = objectPaths.Select(e => (PropertyPathMarker)e);
120120
return this;
121+
}
122+
123+
public StringMappingDescriptor<T> Path(MultiFieldMappingPath path)
124+
{
125+
this._Mapping.Path = path.Value;
126+
return this;
127+
}
128+
129+
public StringMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, CorePropertiesDescriptor<T>> fieldSelector)
130+
{
131+
fieldSelector.ThrowIfNull("fieldSelector");
132+
var properties = fieldSelector(new CorePropertiesDescriptor<T>());
133+
foreach (var p in properties.Properties)
134+
{
135+
var value = p.Value as IElasticCoreType;
136+
if (value == null)
137+
continue;
138+
139+
_Mapping.Fields[p.Key] = value;
140+
}
141+
return this;
121142
}
122143
}
123144
}

0 commit comments

Comments
 (0)