type=mapper_parsing_exception, reason=Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters
时间: 2024-03-05 15:52:44 浏览: 30
这个错误通常是由于在文档中直接添加了 `_id` 字段,而 `_id` 字段是元数据字段,不能直接添加到文档中。相反,您应该使用索引API请求参数指定文档的 `_id` 值。
例如,在使用Elasticsearch的Java客户端API时,您可以使用以下代码将文档添加到索引:
```java
IndexRequest request = new IndexRequest("index_name", "doc_type", "document_id");
request.source(jsonString, XContentType.JSON);
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
```
在这个例子中,您可以看到我们在 `IndexRequest` 中指定了文档的 `_id` 值。在 `source` 方法中,我们可以将文档的JSON表示作为字符串传递,并指定其内容类型为 `XContentType.JSON`。
如果您正在使用REST API,那么您可以使用以下 `PUT` 请求将文档添加到索引:
```
PUT index_name/doc_type/document_id
{
"field1": "value1",
"field2": "value2"
}
```
在这个例子中,我们在请求URL中指定了文档的 `_id` 值,并将文档的JSON表示作为请求体发送。请注意,这个请求仅适用于添加新文档,不能用于更新具有现有 `_id` 值的文档。
相关问题
Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse]
这个错误是由Elasticsearch引起的,它的类型是mapper_parsing_exception,错误的原因是解析映射时出现问题。具体地,根映射定义中包含不受支持的参数。 下面是一个修复后的映射语句的示例:
```
{
"properties": {
"birthday": {
"type": "date",
"store": true
},
"hobby": {
"type": "text",
"store": true
},
"id": {
"type": "long",
"store": true
},
"name": {
"type": "text",
"store": true
}
}
}
```
请确保你的映射语句与你正在使用的Elasticsearch版本兼容。不同的版本可能会有不同的语法和参数支持。 也请注意,在修复错误之前,确保你的Elasticsearch版本号是正确的。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [properties]](https://blog.csdn.net/ozl544578/article/details/125967168)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [ElasticSearch创建索引报错:mapper_parsing_exception Root mapping definition has unsupported ...](https://blog.csdn.net/sun_luming/article/details/120120533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
how to fix Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: no handler for type [icu_collation_keyword] declared on field [so
To fix the Elasticsearch exception of type `mapper_parsing_exception` with the reason "Failed to parse mapping [_doc]: no handler for type [icu_collation_keyword] declared on field [so]," you need to make sure that the ICU plugin is installed and enabled in Elasticsearch.
Here are the steps to follow:
1. Check if the ICU plugin is installed by running the following command in your Elasticsearch bin directory:
```
bin/elasticsearch-plugin list
```
If ICU is not listed, you can install it by running the following command:
```
bin/elasticsearch-plugin install analysis-icu
```
2. Once the ICU plugin is installed, you need to enable it by adding the following configuration to your Elasticsearch configuration file (`elasticsearch.yml`):
```
index.analysis.analyzer.default.type: "custom"
index.analysis.analyzer.default.tokenizer: "icu_tokenizer"
```
3. After making the changes, restart Elasticsearch for the changes to take effect.
Once Elasticsearch restarts, the `icu_collation_keyword` type should be recognized, and the exception should be resolved.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)