zincsearch/zincsearch · error
GetFloatFromMap: key [%s] not found
Error message
GetFloatFromMap: key [%s] not found
What it means
GetFloatFromMap reads a numeric option from a filter settings map (used by dict, edge_ngram, length, ngram, shingle, truncate filters). This error means the required key is not present at all. It is a missing-required-option error surfaced while constructing a token filter.
Source
Thrown at pkg/zutils/map.go:49
}
func GetBoolFromMap(m interface{}, key string) (bool, error) {
v, err := GetAnyFromMap(m, key)
if err != nil {
return false, fmt.Errorf("GetBoolFromMap: key [%s] not found", key)
}
vs, ok := v.(bool)
if !ok {
return false, fmt.Errorf("GetBoolFromMap: value [%s] shuld be a bool", key)
}
return vs, nil
}
func GetFloatFromMap(m interface{}, key string) (float64, error) {
v, err := GetAnyFromMap(m, key)
if err != nil {
return 0, fmt.Errorf("GetFloatFromMap: key [%s] not found", key)
}
vs, ok := v.(float64)
if !ok {
return 0, fmt.Errorf("GetFloatFromMap: value [%s] should be a float64", key)
}
return vs, nil
}
func GetStringSliceFromMap(m interface{}, key string) ([]string, error) {
v, err := GetAnyFromMap(m, key)
if err != nil {
return nil, fmt.Errorf("GetStringSliceFromMap: key [%s] not found", key)
}
var vs []interface{}
switch v := v.(type) {
case []string:
return v, nilView on GitHub (pinned to dd2f8afd65)
Solutions
- Add the missing numeric key (named in the error) to the filter's settings map.
- Check the option name spelling against the filter's documentation.
- Provide defaults for optional numeric params in a wrapper before calling the constructor.
- Validate the filter definition against an expected-option schema before construction.
Example fix
// before
{"type": "ngram"}
// after
{"type": "ngram", "min_gram": 2, "max_gram": 3} Defensive patterns
Strategy: validation
Validate before calling
func requireNumeric(m map[string]interface{}, key string) error {
v, ok := m[key]
if !ok {
return fmt.Errorf("required numeric option %q missing", key)
}
if _, ok := v.(float64); !ok {
return fmt.Errorf("option %q must be a number, got %T", key, v)
}
return nil
}
// requireNumeric(settings, "min_gram") Try / catch
min, err := zutils.GetFloatFromMap(settings, "min_gram")
if err != nil {
if strings.Contains(err.Error(), "not found") {
return fmt.Errorf("ngram filter requires min_gram/max_gram: %w", err)
}
return err
} Prevention
- Keep a per-filter-type required-option checklist (e.g. ngram needs min_gram and max_gram).
- Validate filter definitions against a schema before calling constructors.
- Test each filter definition with a constructor call in unit tests using fixture configs.
- When changing filter types, update the whole option set, not just the type field.
When it happens
Trigger: Calling GetFloatFromMap via NewDictTokenFilter, NewEdgeNgramTokenFilter, NewLengthTokenFilter, NewNgramTokenFilter, NewShingleTokenFilter, or NewTruncateTokenFilter when the settings map lacks the numeric option (e.g. "min_gram", "max_gram", "preserve_original").
Common situations: Writing a token filter definition that omits a required numeric parameter (e.g. an ngram filter with no min_gram); typos in the option name; switching filter types without updating the option set.
Related errors
- GetBoolFromMap: key [%s] not found
- GetStringSliceFromMap: key [%s] not found
- GetMapFromMap: key [%s] not found
- ErrorTypeParsingException
- ErrorTypeParsingException
AI-assisted analysis of zincsearch/zincsearch@dd2f8afd65 (2026-09-03).
Data as JSON: /api/errors/8b35197bb5889610.
Report an issue: GitHub.