How to filter query in solr by date?

前端 未结 3 636
我在风中等你
我在风中等你 2021-02-02 07:27

In my SOLR there is date field(published_date) and values are in this format \"2012-09-26T10:08:09.123Z\"

How I can search by simple input like \"2012-09-10\" i

相关标签:
3条回答
  • 2021-02-02 08:07

    If you want to search simple dd-MM-yyyy so, Your Date - "2012-09-26T10:08:09.123Z"

    In Solr ---Common----- q Date:[26-09-2019 TO 02-10-2019] It gives all data between above range..

    0 讨论(0)
  • 2021-02-02 08:08

    The simplest form of Solr date is the keyword 'NOW' which refers to the current date and time. It is case sensitive in Solr, but the Lucid query parser will permit it to be in any case. 'NOW' can be used either if no explicit date or date math is specified, or it can be used if date math is specified without an explicit date.

    An explicit date is written in Solr using a format based on ISO 8601, which consists of a string of the form yyyy-mm-ddThh:mm:ss.mmmZ, where 'yyyy' is the four-digit year, the first 'mm' is the two-digit month, 'dd' is the two-digit day, 'T' is the mandatory literal letter 'T' to indicate that time follows, 'hh' is the two-digit hours ('00' to '23'), the second 'mm' is the two-digit minutes ('00' to '59'), 'ss' is the two-digit seconds ('00' to '59'), optionally '.mmm' is the three-digit milliseconds preceded by a period, and 'Z' is the mandatory literal letter 'Z' to indicate that the time is UTC ('Zulu'). The millisecond portion, including its leading period, is optional. Trailing zeros are not required for milliseconds.

    For example:
    
        2008-01-01T00:00:00Z
    
        2008-01-01T00:00:00
    
        2008-01-01T00:00 same as [2008-01-01T00:00:00Z TO 2008-01-01T00:00:59Z]
    
        2008-01-01T00: same as [2008-01-01T00:00:00Z TO 2008-01-01T00:59:59Z]
    
        2008-01-01T same as [2008-01-01T00:00:00Z TO 2008-01-01T23:59:59Z]
    
        2008-01-01 same as [2008-01-01T00:00:00Z TO 2008-01-01T23:59:59Z]
    
        2008-01 same as [2008-01-01T00:00:00Z TO 2008-01-31T23:59:59Z]
    
        2008 same as [2008-01-01T00:00:00Z TO 2008-12-31T23:59:59Z]
    

    Credit to Solr Documentation

    0 讨论(0)
  • 2021-02-02 08:10

    If you want to get last week publications you can do somehting like:

    &fq=published_date:[NOW-7DAY/DAY TO NOW]
    

    But if you want a concrete date you must do it in the SOLR date format:

    &fq=published_date:[2013-07-17T00:00:00Z TO NOW]
    

    Last but not least.

    • use [ ] for inclusive ranges
    • use { } for exclusive ranges
    • you can mix them like [ } for inclusive - exclusive and vice versa { ]

    I hope that helps

    0 讨论(0)
提交回复
热议问题