ignore_malformed(忽略格式不对的数据)
有时候你对接受到的数据不会有太多的控制.一个用户可能发送一个日期类型的登录字段,另一个用户发送一个邮箱地址的登录字段.
尝试将错误的数据类型索引到字段中,默认情况会抛出异常,并拒绝整个document(文档).ignore_malformed 参数(如果设置为true)允许忽略该异常。格式不正确的字段不会被索引,但文档中的其他字段正常处理。
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"my_type": {
"properties": {
"number_one": {
"type": "integer",
"ignore_malformed": true
},
"number_two": {
"type": "integer"
}
}
}
}
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
"text": "Some text value",
"number_one": "foo"
}
'
curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type: application/json' -d'
{
"text": "Some text value",
"number_two": "foo"
}
'
1
这个document(文档)会索引text 字段,但不是number_one字段。
2
这个document(文档)会拒绝请求因为number_two不允许格式不正确的值.
ignore_malformed设置允许在相同索引中相同名称的字段有不同的设置。可以使用 PUT mapping API 在现有字段上更新其值。
Index-level default
可以在索引级别上设置 index.mapping.ignore_malformed 的配置,以允许在所有映射类型中全局忽略格式错误的内容.
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"index.mapping.ignore_malformed": true # 1
},
"mappings": {
"my_type": {
"properties": {
"number_one": { # 2
"type": "byte"
},
"number_two": {
"type": "integer",
"ignore_malformed": false # 3
}
}
}
}
}
'
1, 2
number_one字段 继承index-level的配置.
3
number_two字段 覆盖index-level配置来关闭ignore_malformed设置.
Last updated
Was this helpful?