Skip to content

Completion Suggester

The completion suggester provides auto-complete or search-as-you-type functionality. It can return suggestions based on a prefix or a regular expression and supports filtering or boosting with contexts.

Example

import (
    es "github.com/elastic/go-elasticsearch/v8"
    "github.com/sdqri/effdsl/v2"
    cs "github.com/sdqri/effdsl/suggesters/completionsuggester"
)

query, err := effdsl.Define(
    effdsl.WithSuggest(
        cs.CompletionSuggester(
            "song-suggest",
            "nir",
            "suggest",
            cs.WithSize(10),
            cs.WithCompletionSuggesterSkipDuplicates(true),
        ),
    ),
)

res, err := es.Search(
    es.Search.WithBody(strings.NewReader(query)),
)

Parameters

  • SuggestName (string) (Required, positional) Name used to identify the suggestion in the response.
  • Prefix (string) (Required, positional) Prefix text used to generate suggestions. Use CompletionSuggesterRegex for regex input.
  • Field (string) (Required, positional) Completion field from which to fetch suggestions.
  • WithSize(uint64) (Optional, Functional option) Number of suggestions to return. Defaults to 5.
  • WithCompletionSuggesterSkipDuplicates(bool) (Optional, Functional option) Whether duplicate suggestions should be filtered out.
  • WithCompletionSuggesterFuzzy(opt ...FuzzyOption) (Optional, Functional option) Enables fuzzy prefix matching. FuzzyOption functions allow setting fuzziness, prefix length and other parameters.
  • WithRegexFlags(RegexFlag) (Optional, Functional option) Regex flags used with CompletionSuggesterRegex.
  • WithMaxDeterminizedStates(int64) (Optional, Functional option) Maximum allowed states for regex completion.
  • WithMultipleCategoryContext(name, contexts ...string) (Optional, Functional option) Adds category contexts used for filtering or boosting suggestions.
  • WithCategoryContext(name, context string, opts ...CategoryContextClauseOption) (Optional, Functional option) Adds a single category context with optional boost or prefix.
  • WithGeoContext(name string, lat, lon float64, opts ...GeoContextClauseOption) (Optional, Functional option) Adds a geo context for location based suggestions.

Additional Information

For more details on the completion suggester and its parameters, refer to the official Elasticsearch documentation on completion suggesters.