验证一个mapping下字段缺少或者超过
结论: 没有什么不可以.
1.如果数据字段不在mapping里,则动态会更新mapping.
2.数据字段数也可以小于mapping里字段数
- 创建一个mapping
DELETE /lib2
PUT /lib2
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {
"user": {
"properties":{
"name":{"type":"keyword"},
"age":{"type":"integer"},
"address":{"type":"text"},
"birth":{"type":"date"}
}
}
}
}
GET /lib2/_mapping
PUT /lib2/user/1
{
"name":"maotai1",
"age":21,
"address":"shan xi xian",
"birth":"2018-02-06T06:22:59.00Z"
}
- 少两个字段
PUT /lib2/user/2
{
"name":"maotai2",
"age":22
}
- 多一个favor字段
PUT /lib2/user/3
{
"name":"maotai3",
"age":23,
"address":"shan xi xian",
"birth":"2018-02-06T06:22:59.00Z",
"favor":["book","sleep"]
}
- 查询
GET /lib2/user/_search
{
"query": {
"match_all": {}
}
}
以下几种情况都是ok的
mapping字段数 == 数据字段数
mapping字段数 >= 数据字段数
mapping字段数 <= 数据字段数