# ElasticsearchParseException: failed to parse search template [my_template]; error: Mustache syntax error at line 3: unexpected character '}'

- **ID:** `elasticsearch/search-template-parsing-error`
- **Domain:** elasticsearch
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A search template defined in Elasticsearch contains invalid Mustache syntax, such as mismatched braces or incorrect variable interpolation, causing template parsing to fail.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.15.0 | active | — | — |
| 8.7.0 | active | — | — |
| 8.13.0 | active | — | — |

## Workarounds

1. **Retrieve the template definition using GET /_scripts/my_template, fix the Mustache syntax (e.g., replace unmatched '}' with '{{/query}}'), and update it using PUT /_scripts/my_template with the corrected source. Example fix: change '{{#query}} {{field}} }' to '{{#query}} {{field}} {{/query}}'.** (95% success)
   ```
   Retrieve the template definition using GET /_scripts/my_template, fix the Mustache syntax (e.g., replace unmatched '}' with '{{/query}}'), and update it using PUT /_scripts/my_template with the corrected source. Example fix: change '{{#query}} {{field}} }' to '{{#query}} {{field}} {{/query}}'.
   ```
2. **Use an inline template in the search query instead of a stored template to bypass the parsing issue temporarily: GET /_search/template { 'source': { 'query': { 'match': { 'field': '{{value}}' } } }, 'params': { 'value': 'test' } }** (80% success)
   ```
   Use an inline template in the search query instead of a stored template to bypass the parsing issue temporarily: GET /_search/template { 'source': { 'query': { 'match': { 'field': '{{value}}' } } }, 'params': { 'value': 'test' } }
   ```

## Dead Ends

- **** — Re-saving the template with the same invalid syntax will produce the same error; the template must be corrected first. (95% fail)
- **** — Clearing the search template cache via POST /_cache/clear does not fix the underlying template definition. (85% fail)
