简体   繁体   English

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

[英]Search different date format in elastic search

I've indexed a date column from my mysql database with the following configuration 我已经使用以下配置从我的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

How can I query elastic search using different date formats? 如何使用不同的日期格式查询弹性搜索? eg any items that have 2015-10-01 as index should be searchable when I search for 'October 1' or 'Oct 1' 例如,当我搜索“ 10月1日”或“ 10月1日”时,应可搜索所有具有2015-10-01索引的项目

Is there a way to do it in elasticsearch or do I have to format the date before passing it to the finder? 有没有办法在Elasticsearch中做到这一点,或者我必须在将日期传递给查找器之前格式化日期?

You should use a tool to convert the user input into a full Date/DateTime/DateTimeOffset object. 您应该使用工具将用户输入转换为完整的Date / DateTime / DateTimeOffset对象。

In javascript Moment would be a great choice. 在javascript中, Moment是个不错的选择。

In C# DateTimeOffset.TryParse() is your friend. 在C#中,DateTimeOffset.TryParse()是您的朋友。

Whatever language you're using I'm sure there is a built in date conversion library. 无论您使用哪种语言,我都可以肯定有一个内置的日期转换库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM