date fields and invalid date string errors

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

date fields and invalid date string errors

rhys J
I have date fields in my documents that are just YYYY-MM-DD.

I set them as a pdate field in the schema as such:

<fieldType name="pdate" class="solr.DatePointField" docValues="true"/>

and

<field name="next_contact_date" type="pdate" uninvertible="true"
sortMissingLast="true" indexed="true" stored="true"/>

When I use the API to do a search and try:

2018-01-01
[2018-01-01 TO NOW]

I get 'Invalid Date String'.

Did I type my data wrong in the schema? Is there something I'm missing from
the field itself?

According to this page, I should be able to query on just YYYY or YYYY-MM
or YYYY-MM-DD.

https://lucene.apache.org/solr/guide/6_6/working-with-dates.html

Thanks,

Rhys
Reply | Threaded
Open this post in threaded view
|

Re: date fields and invalid date string errors

Shawn Heisey-2
On 11/13/2019 10:07 AM, rhys J wrote:

> I have date fields in my documents that are just YYYY-MM-DD.
> <fieldType name="pdate" class="solr.DatePointField" docValues="true"/>
>
> and
>
> <field name="next_contact_date" type="pdate" uninvertible="true"
> sortMissingLast="true" indexed="true" stored="true"/>
>
> When I use the API to do a search and try:
>
> 2018-01-01
> [2018-01-01 TO NOW]
>
> I get 'Invalid Date String'.
>
> Did I type my data wrong in the schema? Is there something I'm missing from
> the field itself?
>
> According to this page, I should be able to query on just YYYY or YYYY-MM
> or YYYY-MM-DD.

With DatePointField, you must use full date strings, that include time
down to the second.  Here's an example.

2018-01-01T00:00:00

If you use DateRangeField instead of DatePointField for your field's
class, then you can indeed use partial timestamps for both indexing and
querying.  This only works with DateRangeField.

Thanks,
Shawn
Reply | Threaded
Open this post in threaded view
|

Re: date fields and invalid date string errors

rhys J
> If you use DateRangeField instead of DatePointField for your field's
> class, then you can indeed use partial timestamps for both indexing and
> querying.  This only works with DateRangeField.
>
>
I don't see that as an option in the API? Do I need to change what pdate's
type is in the managed-schema for it to take effect?

As in:

 <fieldType name="pdate" class="solr.DatePointField" docValues="true"/>

to

 <fieldType name="pdate" class="solr.DateRangeField" docValues="true"/>

Thanks,

Rhys
Reply | Threaded
Open this post in threaded view
|

Re: date fields and invalid date string errors

Shawn Heisey-2
On 11/13/2019 10:45 AM, rhys J wrote:

>> If you use DateRangeField instead of DatePointField for your field's
>> class, then you can indeed use partial timestamps for both indexing and
>> querying.  This only works with DateRangeField.
>>
>>
> I don't see that as an option in the API? Do I need to change what pdate's
> type is in the managed-schema for it to take effect?
>
> As in:
>
>   <fieldType name="pdate" class="solr.DatePointField" docValues="true"/>
>
> to
>
>   <fieldType name="pdate" class="solr.DateRangeField" docValues="true"/>

You could do it that way ... but instead, I'd create a new fieldType,
not change an existing one.  The existing name is "pdate" which implies
"point date".  I would probably go with "daterange" or "rdate" as the
name, but that is completely up to you.

Note that trying to use an existing index with a new schema is not going
to work.  You're going to need to delete the old index and build it
again after you change the schema.

Thanks,
Shawn
Reply | Threaded
Open this post in threaded view
|

Re: date fields and invalid date string errors

rhys J
> You could do it that way ... but instead, I'd create a new fieldType,
> not change an existing one.  The existing name is "pdate" which implies
> "point date".  I would probably go with "daterange" or "rdate" as the
> name, but that is completely up to you.
>
>
I did that, deleted docs, stopped, started solr, and then re-indexed. And
it's working like I expect it to.

Thanks for the help.

Rhys