# QueryShardException: failed to create query: boost must be positive, got [-2.0]

- **ID:** `elasticsearch/invalid-boost-in-query`
- **Domain:** elasticsearch
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.17.0 | active | — | — |
| 8.10.0 | active | — | — |
| 8.13.0 | active | — | — |

## Workarounds

1. **Change the boost value to a positive float, e.g., in a function_score query: { "function_score": { "query": { "match": { "field": "value" } }, "boost": 0.5 } }** (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 } }
   ```
2. **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)" } } }** (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)" } } }
   ```

## Dead Ends

- **** — Index-time boost is deprecated and ignored; the error is about query-time boost, not mapping boost (70% fail)
- **** — Negative boost is not supported; use a 'must_not' clause or script_score with negation instead (85% fail)
