Skip to content

Term Suggester

The term suggester suggests corrections for individual terms based on edit distance. Each term in the provided text is analyzed, and possible corrections are returned.

Example

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

query, err := effdsl.Define(
    effdsl.WithSuggest(
        ts.TermSuggester(
            "my-suggestion",
            "tring out Elasticsearch",
            "message",
            ts.WithAnalyzer("test"),
            ts.WithSize(1),
            ts.WithSort(ts.ByScore),
            ts.WithMode(ts.Always),
        ),
    ),
)

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

Parameters

  • SuggestName (string) (Required, positional) Name used to identify the suggestion in the response.
  • Text (string) (Required, positional) Text to generate suggestions for.
  • Field (string) (Required, positional) Field to fetch candidate suggestions from.
  • WithAnalyzer(string) (Optional, Functional option) Analyzer used to analyze the suggest text.
  • WithSize(uint64) (Optional, Functional option) Maximum number of suggestions to return.
  • WithSort(TermSuggestSort) (Optional, Functional option) Defines how suggestions are sorted. Possible values: ByScore, ByFrequency.
  • WithMode(TermSuggesterMode) (Optional, Functional option) Controls which suggestions are included. Possible values: Missing, Popular, Always.

Additional Information

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