elasticsearch
type_error
ai_generated
true
QueryShardException: failed to create query: boost must be positive, got [-2.0]
ID: elasticsearch/invalid-boost-in-query
92%Fix Rate
88%Confidence
1Evidence
2023-11-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.17.0 | active | — | — | — |
| 8.10.0 | active | — | — | — |
| 8.13.0 | active | — | — | — |
Root Cause
A negative or zero boost value in a query DSL, such as in a function_score query or term query, violates the requirement that boost must be a positive float.
generic中文
查询DSL中的负值或零提升值(例如在function_score查询或term查询中)违反了提升值必须为正浮点的要求。
Official Documentation
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.htmlWorkarounds
-
95% success Change the boost value to a positive float, e.g., in a function_score query: { "function_score": { "query": { "match": { "field": "value" } }, "boost": 0.5 } }
Change the boost value to a positive float, e.g., in a function_score query: { "function_score": { "query": { "match": { "field": "value" } }, "boost": 0.5 } } -
85% success Use a script_score query with Math.max(boost, 0.01) to ensure positivity: { "script_score": { "query": { "match_all": {} }, "script": { "source": "Math.max(_score, 0.01)" } } }
Use a script_score query with Math.max(boost, 0.01) to ensure positivity: { "script_score": { "query": { "match_all": {} }, "script": { "source": "Math.max(_score, 0.01)" } } }
中文步骤
将提升值改为正浮点数,例如在function_score查询中:{ "function_score": { "query": { "match": { "field": "value" } }, "boost": 0.5 } }使用script_score查询并确保提升值正数:{ "script_score": { "query": { "match_all": {} }, "script": { "source": "Math.max(_score, 0.01)" } } }
Dead Ends
Common approaches that don't work:
-
70% fail
Index-time boost is deprecated and ignored; the error is about query-time boost, not mapping boost
-
85% fail
Negative boost is not supported; use a 'must_not' clause or script_score with negation instead