Skip to content

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

@tommymonk

Description

@tommymonk

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 ?

Activity

flobernd

flobernd commented on Feb 11, 2025

@flobernd
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

tommymonk commented on Feb 11, 2025

@tommymonk
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

flobernd commented on Feb 11, 2025

@flobernd
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.

changed the title [-]Nested mappings no longer support generics nicely?[/-] [+]Feature: Push down generic types when mapping nested properties[/+] on Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tommymonk@flobernd

        Issue actions

          Feature: Push down generic types when mapping nested properties · Issue #8455 · elastic/elasticsearch-net