有时候你对接受到的数据不会有太多的控制.一个用户可能发送一个日期类型的登录字段,另一个用户发送一个邮箱地址的登录字段.
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"
}
'
ignore_malformed设置允许在相同索引中相同名称的字段有不同的设置。可以使用 PUT mapping API 在现有字段上更新其值。
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
}
}
}
}
}
'