Skip to content

How to Use Completion Suggester in Elasticsearch8 #7922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ynanech opened this issue Sep 8, 2023 · 1 comment
Closed

How to Use Completion Suggester in Elasticsearch8 #7922

ynanech opened this issue Sep 8, 2023 · 1 comment
Labels
8.x Relates to a 8.x client version

Comments

@ynanech
Copy link

ynanech commented Sep 8, 2023

Elastic.Clients.Elasticsearch version:8.9.2

Elasticsearch version:8.7.0

.NET runtime version:net7.0

Operating system version:win11

Description of the problem including expected versus actual behavior:

Question 1.

When creating a suggestion field and setting Contexts, the following methods do not take effect:

`

.Completion(t => t.Suggestions, //Settings not effective
t => t.Analyzer("suggest_analyzer")
.Contexts(c => c
.Type("CATEGORY")
.Name("merchantTab")
.Path(cp => cp.MerchantId.Suffix("tab"))
)
)

`
image

The following methods are effective:

`
.Completion(t => t.Suggestions, //Setting is valid
t => t.Analyzer("suggest_analyzer")
.Contexts(new SuggestContext[] {
new SuggestContext
{
Type = "CATEGORY",
Name = $"merchantTab",
Path = new Field("merchantId.tab")
}
})
)

`

image

Question 2.

Suggest doesn't work and won't get any results,But I used the same data, and there were results in Elasticsearch 7.17.5:

`

    public async Task<object> Suggest(string input)
    {
        var suggester = FieldSuggester.Completion(new CompletionSuggester
        {
            Contexts = new Dictionary<Field, ICollection<CompletionContext>> {
                   {"merchantTab", new List<CompletionContext>{ new CompletionContext {
                    Context=new Context (""),
                    Prefix=true,
                   } } }
                 },
            Fuzzy = new SuggestFuzziness
            {
                Fuzziness = new Fuzziness("auto"),
                MinLength = 1,
                PrefixLength = 2,
                Transpositions = true,
                UnicodeAware = false
            },
            Field = "suggestions",
            Size = 10,

            SkipDuplicates = true,
        });
        suggester.Prefix = input;
        //suggester.Text = input;

        string name = "product-suggest";
        var result = await _elasticClient.SearchAsync<ProductInfoDoc8>(m => m
                           .Index("frame.product8x")
                           .Suggest(new Suggester
                           {
                               Suggesters = new Dictionary<string, FieldSuggester> {
                                   { name, suggester}
                               }
                           }
                        ));
        return result.Fields.FirstOrDefault();
    }

`

@ynanech ynanech added the 8.x Relates to a 8.x client version label Sep 8, 2023
@flobernd
Copy link
Member

flobernd commented Sep 8, 2023

Hi there!

  1. This looks like a bug. The descriptor functionality should be equivalent to the object initializer syntax.

  2. The Suggestion property that contains the suggestion results, is currently missing from the search response. I re-implemented this functionality in Reintroduce suggestion feature #7894 which will be included in the next release.

@flobernd flobernd added the bug label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to a 8.x client version
Projects
None yet
Development

No branches or pull requests

2 participants