elasticsearch-net
elasticsearch-net copied to clipboard
Feature: Push down generic types when mapping nested properties
Elastic.Clients.Elasticsearch version: 8.*
Elasticsearch version: 8.*
.NET runtime version: 9
Operating system version: Windows 11
Description of the problem including expected versus actual behavior: The Nest driver used to support mapping nested objects fluently using generics
e.g. descriptor.Nested<SomeType>(n => n.Name(s => s.ListOfSomeType).Properties(s => s.Keyword(k => k.SomePropertyOfSomeType)))
Have I just overlooked how this should be done in the new driver, I have seen other tickets where people mention working around it by using the existing Nested method but using .First().SomePropertyOfSomeType all over the place ?
Hi @tommymonk ,
nested mappings do still support generics, but they always operate on the top-level type:
client.Indices.PutMappingAsync<Person>(x => x
.Properties(x => x
.Nested(p => p.OtherPerson, x => x
.Properties(x => x
.Keyword(p => p.OtherPerson.FirstName) // Nested object: OtherPerson.FirstName
)
)
.Nested(p => p.Numbers, x => x
.Properties(x => x
.IntegerNumber(p => p.Numbers.First()) // Nested array: Numbers.[]
)
)
)
);
Please let me know if that answers your question.
I see, it feels like a step backwards to me from what we had in Nest.
For complex mappings with the same type appearing in multiple parts of the mapping I have separate method that handle that type, it worked nicely.
I've had to spend hours going through changing everything to nameof(Class.Property) because it's just too repetitive and clumsy this new way
It might be worth adding overloads for the nested mappings.
We sadly lost a bit of convenience here and there with the new auto-generated client. Auto mapping is something still on my todo list as well. I'll review this nested mapping case when I finally have time to work on this part.
Keeping this open as a feature request.