You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: metafilter coerces NaN and Infinity strings into non-finite floats, breaking ES/OpenSearch JSON encoding #22698
In internal/engine/metafilter/meta_filter.go, both coerceScalar (used by = and ≠) and coerceRangeValue (used by >, <, ≥, ≤) call strconv.ParseFloat(s, 64) without checking whether the parsed float64 is finite (!math.IsNaN(parsed) && !math.IsInf(parsed, 0)).
In Go, strconv.ParseFloat accepts "NaN", "Inf", "+Inf", "-Inf", "Infinity", "+Infinity", and "-Infinity" case-insensitively and returns non-finite float64 values (NaN, +Inf, -Inf). As a result, filtering metadata on ordinary string values such as engine = "Infinity", department = "Inf", or author = "Nan" embeds a non-finite float64 directly into the generated Elasticsearch/OpenSearch query map:
BuildMetaFilterQuery produces {"term": {"meta_fields.engine": +Inf}} instead of a case-insensitive keyword match {"term": {"meta_fields.engine.keyword": {"value": "infinity", "case_insensitive": true}}}.
When internal/engine/elasticsearch/metadata.go or internal/engine/opensearch/metadata.go JSON-encodes that query via json.NewEncoder(&buf).Encode(requestBody), encoding/json fails with json: unsupported value: +Inf (or NaN / -Inf), causing FilterDocIdsByMetaPushdown to silently abort push-down.
Expected behavior
coerceScalar and coerceRangeValue should only coerce finite numeric values to float64. Non-finite strings like "NaN", "Inf", and "Infinity" should remain strings (lowercased in coerceScalar and matched against .keyword, preserved as strings in coerceRangeValue), producing valid JSON-serializable Elasticsearch/OpenSearch queries.
Steps to reproduce
Call metafilter.BuildMetaFilterQuery([]map[string]interface{}{{"key": "engine", "op": "=", "value": "Infinity"}}, "and", []string{"kb-1"}) (or with "NaN", "Inf", "-Inf", "-Infinity", or with range operators >, <, ≥, ≤).
Call json.Marshal on the returned query map.
Observe json: unsupported value: +Inf (or NaN / -Inf).
Additional information
internal/engine/metafilter is shared by both Elasticsearch and OpenSearch metadata push-down (internal/engine/elasticsearch/metadata.go and internal/engine/opensearch/metadata.go). A fix is ready.
AI-assisted: drafted with an AI coding agent; the tests above were run locally.
Activity