Skip to content

Fixed template mapping: type name wasn't properly inferred #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Nest/DSL/PutTemplateDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ public PutTemplateDescriptor AddMapping<T>(Func<PutMappingDescriptor<T>, PutMapp
where T : class
{
mappingSelector.ThrowIfNull("mappingSelector");
var rootObjectMappingDescriptor = mappingSelector(new PutMappingDescriptor<T>(this._connectionSettings));
rootObjectMappingDescriptor.ThrowIfNull("rootObjectMappingDescriptor");
var putMappingDescriptor = mappingSelector(new PutMappingDescriptor<T>(this._connectionSettings));
putMappingDescriptor.ThrowIfNull("rootObjectMappingDescriptor");

var inferrer = new ElasticInferrer(this._connectionSettings);
var typeName = inferrer.TypeName(rootObjectMappingDescriptor._Type);
var typeName = inferrer.TypeName(putMappingDescriptor._Type ?? typeof(T));
if (typeName == null)
return this;
this._TemplateMapping.Mappings[typeName] = rootObjectMappingDescriptor._Mapping;
this._TemplateMapping.Mappings[typeName] = putMappingDescriptor._Mapping;
return this;

}

public PutTemplateDescriptor AddWarmer<T>(Func<CreateWarmerDescriptor, CreateWarmerDescriptor> warmerSelector)
Expand Down
9 changes: 4 additions & 5 deletions src/Tests/Nest.Tests.Integration/Template/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public void PutTemplateWithMappings()
this._client.DeleteTemplate("put-template-with-mappings");
var putResponse = this._client.PutTemplate("put-template-with-mappings",t => t
.Template("donotinfluencothertests")
.AddMapping<dynamic>(s=>s
.Type("mytype")
.AddMapping<ElasticsearchProject>(s=>s
.AllField(a=>a.Enabled(false))
)
);
Expand All @@ -78,9 +77,9 @@ public void PutTemplateWithMappings()

var mappings = templateResponse.TemplateMapping.Mappings;

Assert.IsTrue(mappings.ContainsKey("mytype"), "put-template-with-mappings template should have a `mytype` mapping");
Assert.NotNull(mappings["mytype"].AllFieldMapping, "`mytype` mapping should contain the _all field mapping");
Assert.AreEqual(false, mappings["mytype"].AllFieldMapping._Enabled, "_all { enabled } should be set to false");
Assert.IsTrue(mappings.ContainsKey("elasticsearchprojects"), "put-template-with-mappings template should have a `mytype` mapping");
Assert.NotNull(mappings["elasticsearchprojects"].AllFieldMapping, "`mytype` mapping should contain the _all field mapping");
Assert.AreEqual(false, mappings["elasticsearchprojects"].AllFieldMapping._Enabled, "_all { enabled } should be set to false");
}

[Test]
Expand Down