Skip to content
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

Feature: Push down generic types when mapping nested properties #8455

Open
tommymonk opened this issue Feb 6, 2025 · 3 comments
Open

Feature: Push down generic types when mapping nested properties #8455

tommymonk opened this issue Feb 6, 2025 · 3 comments
Labels
8.x Relates to 8.x client version Category: Feature Usability

Comments

@tommymonk
Copy link

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 ?

@tommymonk tommymonk added 8.x Relates to 8.x client version Category: Bug labels Feb 6, 2025
@flobernd
Copy link
Member

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.

@tommymonk
Copy link
Author

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

@flobernd
Copy link
Member

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.

@flobernd flobernd changed the title Nested mappings no longer support generics nicely? Feature: Push down generic types when mapping nested properties Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Category: Feature Usability
Projects
None yet
Development

No branches or pull requests

2 participants