1.将对象里面的内容全部映射为关键字
对象里面的 middle 字段除外。
name对象中的字段类型为 keyword, middle 字段除外。
curl -u elastic:elastic -k -XPUT http://192.168.1.800:9200/dynamic_obj -H 'Content-Type: application/json' -d '
{
"mappings":{
"dynamic_templates":[
{
"full_name":{
"path_match":"name.*",
"path_unmatch":"*.middle",
"mapping":{"type":"keyword"}
}
}
]
}}'
2.写入数据
curl -u elastic:elastic -k -XPUT http://192.168.1.800:9200/dynamic_obj/_doc/1 -H 'Content-Type: application/json' -d '
{
"name":{
"first":"shuangqi",
"middle":"Ted",
"last":"betty"
}}'
3.查看结构
curl -u elastic:elastic -k -XGET http://192.168.1.800:9200/dynamic_obj/_mapping
{
"dynamic_obj":{
"mappings":{
"dynamic_templates":[
{
"full_name":{
"path_match":"name.*",
"path_unmatch":"*.middle",
"mapping":{
"type":"keyword"
}
}
}
],
"properties":{
"name":{
"properties":{
"first":{
"type":"keyword"
},
"last":{
"type":"keyword"
},
"middle":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
}
}