gpt4 book ai didi

java - Elasticsearch索引创建异常

转载 作者:行者123 更新时间:2023-12-01 11:11:08 27 4
gpt4 key购买 nike

我正在尝试在 Elastic Search 中创建一个新索引,如下所示

  PUT /abtest2
{
"settings":{

"analysis":{

"char_filter":{

"replaceJunk":{

"type":"pattern_replace",
"pattern":"[^\\d+]",
"replacement":""
}
},

"analyzer":{

"dateAnalyzer":{

"type":"custom",
"tokenizer":"standard",
"char_filter":["replaceJunk"]
}
}

}
},

"mappings":{

"fix":{

"properties": {

"Date": {
"type": "date",
"analyzer": "dateAnalyzer"
}
}
}
}
}

所以基本上,我想为我的日期字段创建一个自定义分析器,其中可能会包含一些非数字字符。现在,我尝试传递一个类似的值

PUT /abtest2/fix/5
{
"Date":"14186196000-0005"
}

但这给了我一个错误

    {
"error": "MapperParsingException[failed to parse [Date]]; nested: MapperParsingException[failed to parse date field [14186196000-0005], tried both date format [dateOptionalTime], and timestamp number with locale []]; nested: IllegalArgumentException[Invalid format: \"14186196000-0005\" is malformed at \"00-0005\"]; ",
"status": 400
}

这个字段不应该被分析和改造吗?

请指教

最佳答案

ElasticSearch 不允许为日期字段指定分析器,而只能为字符串指定分析器。如果您在应用设置后尝试curl http://localhost:9200/abtest2/_mapping,您将看到:

{
"abtest2": {
"mappings": {
"fix": {
"properties": {
"Date": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}
}

分析器已被删除并且未被使用。

在将数据发送到 ES 之前,您需要清理数据,以便将其正确解析为日期。

关于java - Elasticsearch索引创建异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32359007/

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