Skip to content

Commit d656255

Browse files
committed
allow type name to be overridden when adding mappings at index creation
1 parent d2c5bd9 commit d656255

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
@@ -118,7 +118,16 @@ public CreateIndexDescriptor AddMapping<T>(Func<PutMappingDescriptor<T>, PutMapp
118118
typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor");
119119
var d = typeMappingDescriptor(new PutMappingDescriptor<T>(this._connectionSettings));
120120
var typeMapping = d._Mapping;
121-
typeMapping.Name = typeof (T);
121+
122+
if (d._Type != null)
123+
{
124+
typeMapping.Name = d._Type.Name != null ? (PropertyNameMarker)d._Type.Name : d._Type.Type;
125+
}
126+
else
127+
{
128+
typeMapping.Name = typeof(T);
129+
}
130+
122131
this._IndexSettings.Mappings.Add(typeMapping);
123132

124133
return this;
@@ -133,7 +142,16 @@ public CreateIndexDescriptor AddMapping<T>(RootObjectMapping rootObjectMapping,
133142
typeMappingDescriptor.ThrowIfNull("typeMappingDescriptor");
134143
var d = typeMappingDescriptor(new PutMappingDescriptor<T>(this._connectionSettings) { _Mapping = rootObjectMapping,});
135144
var typeMapping = d._Mapping;
136-
typeMapping.Name = typeof (T);
145+
146+
if (d._Type != null)
147+
{
148+
typeMapping.Name = d._Type.Name != null ? (PropertyNameMarker)d._Type.Name : d._Type.Type;
149+
}
150+
else
151+
{
152+
typeMapping.Name = typeof (T);
153+
}
154+
137155
this._IndexSettings.Mappings.Add(typeMapping);
138156

139157
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)