Skip to content

Commit 2b1c694

Browse files
committed
Merge pull request #595 from nordbergm/fix/type_name_cannot_be_overridden
allow type name to be overridden when adding mappings at index creation
2 parents cf56f05 + d656255 commit 2b1c694

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Diff for: src/Nest/DSL/CreateIndexDescriptor.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,16 @@ public CreateIndexDescriptor AddMapping<T>(Func<PutMappingDescriptor<T>, PutMapp
121121
typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor");
122122
var d = typeMappingDescriptor(new PutMappingDescriptor<T>(this._connectionSettings));
123123
var typeMapping = d._Mapping;
124-
typeMapping.Name = typeof (T);
124+
125+
if (d._Type != null)
126+
{
127+
typeMapping.Name = d._Type.Name != null ? (PropertyNameMarker)d._Type.Name : d._Type.Type;
128+
}
129+
else
130+
{
131+
typeMapping.Name = typeof(T);
132+
}
133+
125134
this._IndexSettings.Mappings.Add(typeMapping);
126135

127136
return this;
@@ -136,7 +145,16 @@ public CreateIndexDescriptor AddMapping<T>(RootObjectMapping rootObjectMapping,
136145
typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor");
137146
var d = typeMappingDescriptor(new PutMappingDescriptor<T>(this._connectionSettings) { _Mapping = rootObjectMapping,});
138147
var typeMapping = d._Mapping;
139-
typeMapping.Name = typeof (T);
148+
149+
if (d._Type != null)
150+
{
151+
typeMapping.Name = d._Type.Name != null ? (PropertyNameMarker)d._Type.Name : d._Type.Type;
152+
}
153+
else
154+
{
155+
typeMapping.Name = typeof (T);
156+
}
157+
140158
this._IndexSettings.Mappings.Add(typeMapping);
141159

142160
return this;

Diff for: src/Tests/Nest.Tests.Integration/Indices/IndicesTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ public void CreateIndexUsingDescriptor()
259259
.AddMapping<Person>(m => m
260260
.MapFromAttributes()
261261
)
262+
.AddMapping<Person>(m => m
263+
.MapFromAttributes()
264+
.Type("override")
265+
)
262266
.Analysis(a=>a
263267
.Analyzers(an=>an
264268
.Add("standard", new StandardAnalyzer()

0 commit comments

Comments
 (0)