Let's assume folowing class which I want to index:
private class User
{
public User()
{
Id = Guid.NewGuid();
Added = DateTime.Now;
}
public Guid Id { get; protected set; }
public string LastName { get; set; }
public DateTime Added { get; protected set; } // Unimportant for search
}
The point is that I need just the Id
and LastName
property in the index. Using the fluent api everything works fine (just the specified properties will be mapped):
_client.Map<User>(m => m.
Index("nest_test").
Properties(p => p.String(s => s.Name(u => u.LastName))));
Now, when I index an object the mapping will be extended by the remaining properties. How can I avoid these behavior. (Also odd for me: MapFromAttributes()
maps all of the properties, while not even one property is decorated?!).
This is a very little example but some of my domain objects stand in many-many-relations. I didn't try it but I don't think it's possible to map these objects when everything will be committed.
Copied from the answer in https://github.com/elastic/elasticsearch-net/issues/1278:
This is due to the dynamic mapping behavior of ES when it detects new fields. You can turn this behavior off by setting
dynamic: false
orignore
in your mapping:Keep in mind though, the property will still be present in
_source
.Alternatively, you can use the fluent ignore property API mentioned above, which will exclude the property entirely from the mapping and
_source
since doing so will cause it to not undergo serialization:or less ideal, just stick Json.NET's
[JsonIgnore]
attribute on the properties you want to exclude.