gpt4 book ai didi

date - Elasticsearch:直观的日期搜索

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

我有日期类型的dt_birth属性。我希望能够以不同的方式搜索日期。例如1/13 / 1992、01 / 13 / 1992、1-13-1992、1992年1月13日。我该如何处理?目前,我只能按以下实现的格式进行搜索:

dt_birth: {
type: 'date',
format: 'strict_date_optional_time||epoch_millis'
},

++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++
更新:我有一些问题理解这一点。
对于dt_birth格式:
dt_birth: {
type: 'date',
format: 'strict_date_optional_time||epoch_millis'
}

“strict_date_optional_time || epoch_millis”上方指定的格式如何影响以下指定的查询格式:
{
"query": {
"range": {
"dt_birth": {
"gte": "01/13/1992",
"lte": "1-13-1992",
"format": "d/MM/yyyy||dd/MM/yyyy||d-MM-yyyy||dd-MM-yyyy"
}
}
}
}

另外,当您说添加需要支持的日期格式时,我有点困惑。格式如何对应LTE和GTE?例如,我想接受日期格式2000年1月15日-1/15/2000-01/15/200-1-15-2000-01-15-2000。如果我希望支持5种不同的格式,那是否意味着我需要5个GTE / LTE?最后两个问题最令人困惑。感谢您的帮助:)

最佳答案

dt_birth字段的定义包含ES希望在索引文档时在其中找到的日期格式,以便它可以检索毫秒数(很长)并对其进行索引。

在查询时,您可以选择通过使用 format queryrange属性指定任何其他日期格式来按日期搜索:

{
"query": {
"range": {
"dt_birth": {
"gte": "01/13/1992",
"lte": "1-13-1992",
"format": "d/MM/yyyy||dd/MM/yyyy||d-MM-yyyy||dd-MM-yyyy"
}
}
}
}

要么
{
"query": {
"range": {
"dt_birth": {
"gte": "1/13/1992",
"lte": "January 13, 1992",
"format": "d/MM/yyyy||MMMM dd, yyyy"
}
}
}
}

您可以简单地在 format属性中添加查询时需要支持的所有日期格式,然后在 gtelte属性中填充适当的日期。 ES会很乐意解析它们。

关于date - Elasticsearch:直观的日期搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35948030/

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