无论才能、知识多么卓著,如果缺乏热情,则无异纸上画饼充饥,无补于事。

ES bool型无法使用ignore_malformed忽视格式错误

匿名 | 发布于2022年07月15日 | 阅读数:1244

小白刚学ES。版本ES6.7

数字和字符串类型都可以使用ignore_malformed忽略格式错误,ES6.7文档说明了ignore_malformed无法应用于obiect、nested和range类型上。刚才测试bool型报错,请问大佬们是什么原因造成的。
源代码:
curl -X DELETE "localhost:9200/ignore_malformed_nested_index?pretty";

curl -X PUT "localhost:9200/ignore_malformed_nested_index?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"index.mapping.ignore_malformed": true
},
"mappings": {
"default_type_": {
"properties": {
"ismale": {
"type": "boolean"
}
}
}
}
}
';

curl -X PUT "localhost:9200/ignore_malformed_nested_index/default_type_/1?pretty" -H 'Content-Type: application/json' -d'
{
"ismale": 123
}
';

报错:
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "failed to parse field [ismale] of type [boolean] in document with id '1'"
}
],
"type" : "mapper_parsing_exception",
"reason" : "failed to parse field [ismale] of type [boolean] in document with id '1'",
"caused_by" : {
"type" : "json_parse_exception",
"reason" : "Current token (VALUE_NUMBER_INT) not of boolean type\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@2e3bfbf5; line: 3, column: 16]"
}
},
"status" : 400
}

经测试还发现,数字型或者字符串型设置ignore_malformed=true后,插ture/false,仍报相同错误,插"true"/"false",不报错(估计当作字符串了)
已邀请:

Charele - Cisco4321

赞同来自:

index.mapping.ignore_malformed
好像只对某些类型起作用,比如数字,日期的,
 
这玩意个人感觉没用。报错更好,至少让你知道错了及时处理。

要回复问题请先登录注册