How do I set the number of results return from completion/suggest?

540 Views Asked by At

Currently, I have the Elasticsearch service running on version 7.4.0 while my C# Windows Form application is using Elasticsearch.Net version 7.3.1.

I notice I could set the maximum number of results returned from highlight by setting NumberOfFragments which by default is five. However, I could not get the completion/suggestion to return more than five results when I set the following:

                    var tRes = client.Search<Words>(s => s
                        .SuggestSize(20) // How many suggestions to return in response
                        .Suggest(su => su
                        .Completion("name", cs => cs
                                .SkipDuplicates(true)
                                .Field(f => f.Suggest)
                                .Prefix(tbInput.Text)
                                .Regex("*")
                                .Size(20))
                        )

I received the following error message when I execute the above query.

{"The remote server returned an error: (400) Bad Request.. Call: Status code 400 from: POST /docproperty/_search?typed_keys=true&suggest_size=20. ServerError: Type: illegal_argument_exception Reason: \"request [/docproperty/_search] contains unrecognized parameter: [suggest_size] -> did you mean [suggest_field]?\""}

Update

I manage to get more than 5 results by adding the following:

                    var tRes = client.Search<Words>(s => s
                        .Size(20)
                        .Suggest(su => su
                        .Completion("name", cs => cs
                                .SkipDuplicates(true)
                                .Field(f => f.Suggest)
                                .Prefix(tbInput.Text)
                                .Regex("*")
                                .Size(20))
                                .Term("", t=>t.ShardSize(20).Field(f=>f.Suggest).Text(tbInput.Text))
                        )
                    );

However, this time I notice that I could not get the completion to return words (a lot of missing ones) that could be found when I execute a MatchPhrase.

1

There are 1 best solutions below

2
Abd Rmdn On

I think if you look at the documentation, I think it's not meant to be suggestSize. I think it should be size only.. not sure if this supports chaining.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html