lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <>
Subject Re: Date Query Confusion
Date Thu, 17 May 2018 15:02:31 GMT
Yeah, dates are "special".

Those abbreviated dates are for DateRangeField, which is a distinct
type from "TrieDate" in your schema.

bq. And Solr doesn't seem to let me sort on a date field

It's not a date field that's the problem, it's the "multiValued" part.
When you specify in your schema that the field is multiValued, it
means you can have more than one date in the doc. So how should it be
sorted? Newest first? Oldest first? Whatever you choose is wrong.
Again it's a schema change, set multiValued="false". You _might_ be
able to solve both problems by sorting via a function query (warning,
haven't tried this lately with date fields but "it should work"), see: The
problem there is it must be a docValues="true" field.

This is why we strongly recommend against using "schemaless" mode in
production, schemaless makes the best decision it can, but pretty soon
you want run into issues like these when your intended use isn't

bq.  {!term f=creation_date}2016-10-26T07:59:09.824Z

Well, "it works on my machine", I admit I had a Solr 6.1 version lying
around and used the techproducts example where the date field is
defined as:
type="date"    indexed="true"  stored="true"
and "date" is:
<fieldType name="date" class="solr.TrieDateField" docValues="true"
precisionStep="0" positionIncrementGap="0"/>

The "tdate" field should work identically.

The critical bits here I believe are docValues=true and
multiValued=false by default.

So I'd start by trying the techproducts example "bin/solr start -e
techproducts" which will create docs as I did, and see if you have the
same problem, then use a similar field definition for your real

And if you do change the schema, you need to blow away the entire
index "rm -rf core/data" or create a new collection if using SolrCloud
and re-index.


On Thu, May 17, 2018 at 9:11 AM, Terry Steichen <> wrote:
> To me, one of the more frustrating things I've encountered in Solr is
> working with date fields.  Supposedly, according to the documentation,
> this is straightforward.  But in my experience, it is anything but
> that.  In particular, I've found that the abbreviated forms of date
> queries, don't work as described.
> If I create a query like creation_date: [2016-10-01 To 2016-11-01], it
> will produce a set of documents produced in the month of November 2016.
> That's the good news.
> But, the abbreviated date queries (described in Solr documentation
> <>)
> don't work.  Tried creation_date: 2016-11.  That's supposed to match
> documents with any November 2016 date.  But actually produces:
> |"Invalid Date String:'2016-11'|
> ||And Solr doesn't seem to let me sort on a date field.  Tried
> creation_date asc  Produced: |"can not sort on multivalued field:
> creation_date"|
> In the AdminUI, if you go to the schema option for my collection, and
> examine creation_date it show it to be:
> org.apache.solr.schema.TrieDateField  (This was automatically chosen by
> the managed-schema)
> In that same AdminUI display, if I click "Load Term Info" I get a list
> of dates, but when I click on one, it transforms it into a different
> query form: {!term f=creation_date}2016-10-26T07:59:09.824Z  But this
> query still produces 0 hits (even though the listing says it should
> produce dozens of hits).
> I imagine that I'm missing something basic here.  But I have no idea
> what.  Any thoughts would be MOST welcome.
> PS: I'm using Solr 6.6.0.

View raw message