# ElasticsearchException：验证失败：1: 未指定索引；2: 未指定源；

- **ID:** `elasticsearch/action-request-validation-error`
- **领域:** elasticsearch
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

API请求缺少必需参数，如索引名称或请求体，导致验证失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| elasticsearch 7.0.0 | active | — | — |
| elasticsearch 8.0.0 | active | — | — |
| elasticsearch 8.12.0 | active | — | — |

## 解决方案

1. ```
   确保请求包含'index'和'body'参数。例如在Python中：es.index(index="my_index", body={"field": "value"})
   ```
2. ```
   使用正确的路径和请求体调用REST API：POST /my_index/_doc { "field": "value" }
   ```
3. ```
   如果使用批量API，检查每个操作行是否包含'_index'和'_source'字段。
   ```

## 无效尝试

- **** — An empty body may still pass validation but can cause indexing errors if required fields are missing. (30% 失败率)
- **** — Retrying without fixing the missing parameters will always fail with the same validation error. (100% 失败率)
- **** — HTTP method does not change required parameters; validation is based on the API endpoint and body. (90% 失败率)
