# Elasticsearch解析异常：无法解析搜索模板 [my_template]；错误：第3行Mustache语法错误：意外的字符 '}'

- **ID:** `elasticsearch/search-template-parsing-error`
- **领域:** elasticsearch
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

Elasticsearch中定义的搜索模板包含无效的Mustache语法，例如不匹配的花括号或错误的变量插值，导致模板解析失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.15.0 | active | — | — |
| 8.7.0 | active | — | — |
| 8.13.0 | active | — | — |

## 解决方案

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}}'.
   ```
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' } }
   ```

## 无效尝试

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