.NET new client migration issue

Hi,
I am currently using v7 Elastic .NET client Nest. I want to migrate to the new Elastic.Client.Elasticsearch package v8. I have problems with this package's documentations and I can not find proper docs to use this package so I had to ask my question here.

How can I rewrite the following query writen with Nest using the new .NET client?

var suggestResponse = await _client.SearchAsync<MyDocument>(s => s
    .Suggest(su => su
        .Phrase("simple_phrase", ph => ph
            .Text(searchPhrase)
            .Field(f => f.Title.Suffix("shingle"))
            .Size(5)
            .Confidence(1)
            .DirectGenerator(dg => dg
                .Field(f => f.Title.Suffix("shingle"))
                .PrefixLength(0)
            )
            .MaxErrors(2)
            .Collate(co => co
                .Query(q => q
                    .Source("{\"match\": {\"title\": {\"query\": \"{{suggestion}}\", \"fuzziness\": \"1\", \"operator\": \"and\"}}}")
                )
                .Prune(false)
            )
        )
    )
);

Thanks in advanced.

@jahedi Something like this should work:

var suggestResponse = await _client.SearchAsync<MyDocument>(s => s
    .Suggest(su => su
        .Suggesters(sus => sus
            .Add("simple_phrase", sug => sug
                .Phrase(ph => ph
                    .Text(searchPhrase)
                    .Field(f => f.Title.Suffix("shingle"))
                    .Size(5)
                    .Confidence(1)
                    .DirectGenerator(dg => dg
                        .Field(f => f.Title.Suffix("shingle"))
                        .PrefixLength(0)
                    )
                    .MaxErrors(2)
                    .Collate(co => co
                        .Query(q => q
                            .Source("{\"match\": {\"title\": {\"query\": \"{{suggestion}}\", \"fuzziness\": \"1\", \"operator\": \"and\"}}}")
                        )
                        .Prune(false)
                    )
                )
            )
        )
    )
);

While there is little documentation for the new client, the API almost always maps closely to the structure of the REST API.

1 Like

@flobernd Thanks for your response.
This code does not have syntax errors but I get this exception after executing this query:

Message: Request failed to execute. Call: Status code 400 from: POST /_search?pretty=true&error_trace=true&typed_keys=true. ServerError: Type: parsing_exception Reason: "suggester[phrase] doesn't support field [text]"

{Unsuccessful (400) low level call on POST: /_search?pretty=true&error_trace=true&typed_keys=true Exception: Request failed to execute. Call: Status code 400 from: POST /_search?pretty=true&error_trace=true&typed_keys=true. ServerError: Type: parsing_exception Reason: "suggester[phrase] doesn't support field [text]"}

I had no such problem with the previous code

Can somebody please answer this question? I really can't solve and debug this issue by myself because of the lack of documentations and examples in this area.

Thanks in advance.