Migrating code from ElasticSearch.Net 7 to Elastic.Clients.Elasticsearch 8

Hi!

I’m rewriting our code for the new Elastic.Client.Elasticsearch and I’m trying to find some code examples how to do that.
For example we have a lot of queries like this one:

> var response = _client.Search<TDocument>(s => s 
>             .Index(_client.GetIndexName(TargetIndex.Current, IndexBaseName))
>             .Query(q => (q
>                 .MultiMatch(mm => mm
>                     .Query(query)
>                     .Fields(fields => fields
>                         .Field(nameof(IDocumentModel.Title).ToLowerCamelCase(), 4)
>                         .Field(nameof(IDocumentModel.Preamble).ToLowerCamelCase()))) || q
>                 .MatchPhrase(m => m
>                     .Query(query)
>                     .Boost(2)
>                     .Field(nameof(IDocumentModel.Phonetics).ToLowerCamelCase())) || q
>                 .Match(m => m
>                     .Query(query)
>                     .Field(nameof(IDocumentModel.ContentLink).ToLowerCamelCase())) || q
>                 .MatchPhrasePrefix(m => m
>                     .Query(query)
>                     .Field(nameof(IDocumentModel.Id).ToLowerCamelCase()))) && +q
>                 .Match(t => t
>                     .Field(nameof(IDocumentModel.ParentTypeName).ToLowerCamelCase())
>                     .Query(type)))
>                 .Take(maxResults));

How would that be rewritten? I just cannot figure it out.

We also use the QueryContainer a lot from Nest, what is equal to that in the new code?

Thanks!

/Kristoffer

4 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.