说我有一个对象的映射,因为映射是:
{"my_type":
{"properties":
{"name":{"type":"string","store":"yes","index":"not_analyzed"},
"more":{"type":"object",
"properties":{"a_known_number":{"type":"long","index":"yes"},
"some_json_object":{"type":"object"}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道"some_json_object"会有哪些子字段,但我知道我只想存储这个对象,而不是索引它的任何子字段.我可不可以做:
{"my_type":
{"properties":
{"name":{"type":"string","store":"yes","index":"not_analyzed"},
"more":{"type":"object",
"properties":{"a_known_number":{"type":"long","index":"yes"},
"some_json_object":{"type":"object","store":"yes","index":"no"}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
并影响所有生成的子字段?
不,您不能将整个"对象"指定为未编入索引.但是,您可以使用dynamic_templates(http://www.elasticsearch.org/guide/reference/mapping/root-object-type/)来执行此操作:
{
"my_type":{
"properties":{
"name":{
"type":"string",
"store":"yes",
"index":"not_analyzed"
}
},
"dynamic_templates":[
{
"stored_json_object_template":{
"path_match":"some_json_object.*",
"mapping":{
"store":"yes",
"index":"no"
}
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
这告诉映射器将"some_json_object"的所有属性映射为存储的字符串.
更新 映射中的已删除类型以匹配所有属性类型(match_path => path_match).
更新2 如果您随后创建索引:
{
"mappings":{
"my_type":{
"properties":{
"name":{
"type":"string",
"store":"yes",
"index":"not_analyzed"
}
},
"dynamic_templates":[
{
"stored_json_object_template":{
"path_match":"some_json_object.*",
"mapping":{
"store":"yes",
"index":"no"
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
并索引一个对象:
{
"Name":"Henrik",
"some_json_object":{
"string":"string",
"long":12345
}
}
Run Code Online (Sandbox Code Playgroud)
然后它将获得以下映射:
{
"testindex":{
"my_type":{
"dynamic_templates":[
{
"stored_json_object_template":{
"mapping":{
"index":"no",
"store":"yes"
},
"path_match":"some_json_object.*"
}
}
],
"properties":{
"name":{
"type":"string",
"index":"not_analyzed",
"store":true,
"omit_norms":true,
"index_options":"docs"
},
"some_json_object":{
"properties":{
"long":{
"type":"long",
"index":"no",
"store":true
},
"string":{
"type":"string",
"index":"no",
"store":true
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2788 次 |
| 最近记录: |