//写入文档,查看mapping
PUT mapping_test/_doc/1
{
"firstName":"Chan",
"lastName":"Jackie",
"loginDate":"2018-07-24T10:29:48.103Z"
}
//查看Mapping文件
GET mapping_test/_mapping
//DELETE index
DELETE mapping_test
//dynamic mapping,推断字段的类型
PUT mapping_test/_doc/1
{
"uid":"123",
"isVip":false,
"isAdmin":"true",
"age":19,
"heigh":180
}
//查看dynamic mapping
GET mapping_test/_mapping
//默认Mapping支持dynamic,写入的文档中加入新的字段
PUT dynamic_mapping_test/_doc/1
{
"newField":"someValue"
}
POST dynamic_mapping_test/_search
{
"query": {
"match": {
"newField": "someValue"
}
}
}
//修改dynamic为false
PUT dynamic_mapping_test/_mapping
{
"dynamic":false
}
//新增 anotherField
PUT dynamic_mapping_test/_doc/10
{
"anotherField":"someValue"
}
//该字段不可被搜索,因为dynamic已经被置为false
POST dynamic_mapping_test/_search
{
"query": {
"match": {
"anotherField": "someValue"
}
}
}
GET dynamic_mapping_test/_mapping
//修改dynamic为strict
PUT dynamic_mapping_test/_mapping
{
"dynamic":"strict"
}
//写入数据出错,HTPP code 400
PUT dynamic_mapping_test/_doc/12
{
"lastField":"Value"
}
DELETE dynamic_mapping_test