gpt4 book ai didi

elasticsearch - 7.x版本中的Elasticsearch日期解析错误

转载 作者:行者123 更新时间:2023-12-03 02:19:19 24 4
gpt4 key购买 nike

我使用Elasticsearch 7.1,我在索引映射中定义了格式,如下所示:

 "ManufacturerDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'|| yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'||yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
}
但是即时搜索日期时出现日期解析错误-“2020-07-09T00:12:22.011-00:00”。格式yyyy-MM-dd'T'HH:mm:ss.SSSXXX已定义为可接受的格式之一。
错误是
Failed to parse date field [2020-07-09T00:12:22.011-00:00] with format [yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'||yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'||yyyy-MM-dd'T'HH:mm:ss.SSSXXX]: 
谁能帮忙吗?

最佳答案

添加带有映射和搜索查询的工作示例。
要了解有关Date数据类型的更多信息,请引用此documentation
下面提到的搜索查询用于查找确切的日期类型值。

要返回包含提供范围内的术语的文档,请引用this
映射:

    {
"mappings": {
"properties": {
"ManufacturerDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'||yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
}
}
}
}
搜索查询:
    {
"query": {
"term": {
"ManufacturerDate": {
"value": "2020-07-09T00:12:22.011-00:00"
}
}
}
}'
搜索结果:
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"ManufacturerDate": "2020-07-09T00:12:22.011-00:00"
}
}
]
更新1:
您甚至可以使用 Constant score query
搜索查询:
 {
"query": {
"constant_score": {
"filter": {
"term": {
"ManufacturerDate": "2020-07-09T00:12:22.011-00:00"
}
},
"boost": 1.2
}
}
}
搜索结果:
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 1.2,
"_source": {
"ManufacturerDate": "2020-07-09T00:12:22.011-00:00"
}
}
]
更新2:通过更改模式的顺序,查询有效(使用ES版本7.2)
映射:
    {
"mappings": {
"properties": {
"ManufacturerDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSXXX||yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'||yyyy-MM-dd'T'HH:mm:ss.SSS"
}
}
}
}
索引数据:
    {
"ManufacturerDate": "2020-07-09T00:12:22.011-00:00"
}
搜索查询:
 {
"query": {
"constant_score": {
"filter": {
"term": {
"ManufacturerDate": "2020-07-09T00:12:22.011-00:00"
}
},
"boost": 1.2
}
}
}
搜索结果:
"hits": [
{
"_index": "my_index5",
"_type": "_doc",
"_id": "1",
"_score": 1.2,
"_source": {
"ManufacturerDate": "2020-07-09T00:12:22.011-00:00"
}
}
]

关于elasticsearch - 7.x版本中的Elasticsearch日期解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62808620/

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