Elasticsearch Date字段的默认值

我正在使用以下方法在ES中创建动态映射:

{

"template": "infobox*",

"mappings": {

"_default_": {

"dynamic_templates": [

{

"string_fields": {

"match": "*",

"match_mapping_type": "string",

"mapping": {

"type": "string",

"index": "analyzed",

"analyzer": "my_completion_analyzer",

"fielddata": {

"format": "disabled"

},

"fields": {

"raw": {

"type": "string",

"index": "not_analyzed",

"ignore_above": 256

}

}

}

}

}

]

}

}

}

因此,每当我为具有date字段(birthYear)的文档建立索引时,它都会自动创建birthYear具有date类型的字段()。因此,每当没有a时birthYear,我都会发送一个空字符串'',然后引发异常mapper_parsing_exception,

failed to parse [birthYear]

有什么办法可以解决这个问题?我可以指定默认值吗?

回答:

您可以添加ignore_malformed: true到所有date字段,也可以全局设置:

  "dynamic_templates": [

{

"string_fields": {

"match": "*",

"match_mapping_type": "string",

"mapping": {

"type": "string",

"index": "analyzed",

"analyzer": "whitespace",

"fielddata": {

"format": "disabled"

},

"fields": {

"raw": {

"type": "string",

"index": "not_analyzed",

"ignore_above": 256

}

}

}

}

},

{

"date_fields": {

"match": "*",

"match_mapping_type": "date",

"mapping": {

"type": "date",

"ignore_malformed": true

}

}

}

]

{

"settings": {

"index.mapping.ignore_malformed": true

},

"mappings": {

"_default_": {

"dynamic_templates": [

{

"string_fields": {

"match": "*",

"match_mapping_type": "string",

"mapping": {

"type": "string",

"index": "analyzed",

"analyzer": "whitespace",

"fielddata": {

"format": "disabled"

},

"fields": {

"raw": {

"type": "string",

"index": "not_analyzed",

"ignore_above": 256

}

}

}

}

}

]

}

}

}

以上是 Elasticsearch Date字段的默认值 的全部内容, 来源链接: utcz.com/qa/434391.html

回到顶部