gpt4 book ai didi

elasticsearch - Elasticsearch Date字段的默认值

转载 作者:行者123 更新时间:2023-12-03 00:14:52 25 4
gpt4 key购买 nike

我正在使用以下方法在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)。因此,每当我没有 birthYear时,我都会发送一个空字符串 '',然后引发一个异常 mapper_parsing_exception, failed to parse [birthYear]

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

最佳答案

您可以将ignore_malformed: true添加到所有date字段,或在全局范围内进行设置:

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 - Elasticsearch Date字段的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37185131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com