我正在尝试创建一个适用于字符串字段或日期字段的动态映射,
{
"xx": {
"mappings": {
"dynamic_templates": [
{
"dates": {
"match": "*",
"match_mapping_type": "date*",
"mapping": {
"type": "date",
"format": "YYYY-mm-dd",
"doc_values": true
}
},
"string_fields": {
"mapping": {
"index": "not_analyzed",
"store": false,
"doc_values": true,
"type": "string"
},
"match": "*",
"match_mapping_type": "string"
}
}
]
}
}
}
但是当我将它应用于索引时,“日期”部分缺失,只剩下string_fields,
这里发生了什么?
答案 0 :(得分:0)
日期映射:
"dynamic_date_formats": [
"yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"YYYY-mm-dd"
],
YYYY-mm-dd
,这是您要为日期字段匹配的格式。
答案 1 :(得分:0)
不确定您是如何将该映射应用于索引的,但正确的方法是针对名为test_index
的索引和名为test_type
的类型:
PUT /test_index
{
"mappings": {
"test_type": {
"dynamic_templates": [
{
"dates": {
"match": "*",
"match_mapping_type": "date*",
"mapping": {
"type": "date",
"format": "YYYY-mm-dd",
"doc_values": true
}
}
},
{
"string_fields": {
"mapping": {
"index": "not_analyzed",
"store": false,
"doc_values": true,
"type": "string"
},
"match": "*",
"match_mapping_type": "string"
}
}
]
}
}
}
答案 2 :(得分:-1)
"dynamic_date_formats": [
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"],
"dynamic_templates":[
{
"string_fields": {
"mapping": {
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"match": "*"
}],