在弹性搜索中搜索不同的日期格式

时间:2015-10-02 07:22:41

标签: symfony elasticsearch foselasticabundle

我使用以下配置从我的mysql数据库索引了一个日期列

                    mappings:
                    first_name: { boost: 5 , type: string, index: not_analyzed }
                    last_name: { boost: 5, type: string, index: not_analyzed}
                    id:
                        type: integer
                    date_create:
                        type: date
                        format: YYYY-MM-dd'T'HH:mm:ssZ

如何使用不同的日期格式查询弹性搜索? 例如当我搜索“10月1日”或“10月1日”时,任何以2015-10-01为索引的项目都应该是可搜索的

有没有办法在elasticsearch中执行此操作,或者在将日期传递给finder之前是否必须格式化日期?

1 个答案:

答案 0 :(得分:0)

您应该使用工具将用户输入转换为完整的Date / DateTime / DateTimeOffset对象。

在javascript中Moment将是一个很好的选择。

在C#DateTimeOffset.TryParse()是你的朋友。

无论您使用何种语言,我都确定有内置的日期转换库。

相关问题