Mehmet Serkan Ekinci
Mehmet Serkan Ekinci

Reputation: 129

Make manual mapping with Elastic.Clients.Elasticsearch library in .NET 6

I want to do fluent mapping in my .NET Core 6 project with Elastic.Clients.Elasticsearch library, but I couldn't find anything in the documentation.

Usage in NEST library:

var createIndexResponse = _client.Indices.Create("myindex", c => c
     .Map<Company>(m => m
         .Properties(ps => ps
             .Text(s => s
                 .Name(n => n.Name)
             )
             .Object<Employee>(o => o
                 .Name(n => n.Employees)
                 .Properties(eps => eps
                     .Text(s => s
                         .Name(e => e.FirstName)
                     )
                     .Text(s => s
                         .Name(e => e.LastName)
                     )
                     .Number(n => n
                         .Name(e => e.Salary)
                         .Type(NumberType.Integer)
                     )
                 )
             )
         )
     )
 );

Is there a way to use the above example with the Elastic.Clients.Elasticsearch library? There is no method called Map in this library.

Or what is the method I can resort to to do this? Should I go back to the NEST library?

Upvotes: 1

Views: 146

Answers (1)

GermanSniper
GermanSniper

Reputation: 269

Old question but you should use Mappings method with v8.

var response = await client.Indices.CreateAsync<Person>(Index, c => c
    .Mappings(map => map
        .Properties(p => p
            .Text(t => t.Id, c => c
                .Fields(f => f
                    .Keyword(k => k, cc => cc
                        .IgnoreAbove(256)
                    )
                )
            )
        )
        .Properties(p => p
            .Text(t => t.City, c => c
                .Fields(f => f
                    .Keyword(k => k, cc => cc
                        .IgnoreAbove(256)
                    )
                )
            )      
        )
    )
);

Upvotes: 0

Related Questions