作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有日期类型的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: {
type: 'date',
format: '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"
}
}
}
}
最佳答案
dt_birth
字段的定义包含ES希望在索引文档时在其中找到的日期格式,以便它可以检索毫秒数(很长)并对其进行索引。
在查询时,您可以选择通过使用 format
query的range
属性指定任何其他日期格式来按日期搜索:
{
"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
属性中添加查询时需要支持的所有日期格式,然后在
gte
和
lte
属性中填充适当的日期。 ES会很乐意解析它们。
关于date - Elasticsearch:直观的日期搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35948030/
我是一名优秀的程序员,十分优秀!