Bug with static indexes and dates as string values

41 views
Skip to first unread message

Charles Solar

unread,
Sep 1, 2015, 12:50:00 AM9/1/15
to RavenDB - 2nd generation document database
I may have stumbled onto a bug with static indexes - but there is a workaround.

In my project I am indexing a string field, this field can be a number, text, a date, or pretty much anything.  The problem happens if its a date!

If I save the following object into RavenDB


   
{
 
AnalyzerId {c0273147-2816-4d44-a7db-2f2e14bc73fd} System.Guid
 
Bucket "2015-08-31T23:32:00-05:00" string
 
BucketId {ce6dd8c1-08b3-4e38-99ef-6392f5fe4ebe} System.Guid
 
Data 9 double
 
Id {20632dfe-1af1-4bf8-906d-7cd90d4cd16b} System.Guid
 
Stamp {8/31/2015 11:32:09 PM} System.DateTime
   
}


With the following static index defined:


                    Map = buckets => from b in buckets
                                     select new
                                     {
                                         Id = b.Id,
                                         AnalyzerId = b.AnalyzerId,
                                         Stamp = b.Stamp,
                                         Bucket = b.Bucket,
                                         BucketId = b.BucketId
                                     },
                                   Indexes = {
                        { x => x.Bucket, FieldIndexing.NotAnalyzed },
                        { x => x.BucketId, FieldIndexing.NotAnalyzed },
                        { x => x.AnalyzerId, FieldIndexing.NotAnalyzed }
                    }

The index is populated with AT FIRST seems like correct data - but if you take a look at the terms under the index in the web client, the value of BUCKET is listed as "2015-08-31T23:32:00.0000000-05:00"


Which might be logically equal to what I saved, but not exact - causing a later query for "2015-08-31T23:32:00-05:00" to return no results :(


I think obviously RavenDB is automatically analyzing the input and determining its a date and formatting it appropriately, but I do need to be able to query for what I saved and get results!


The workaround I've done at the moment is to convert the string I am saving into DateTime ticks instead of a ISO string.  So I send along a long number string instead of a date string - this allows me to query for the value later but I hope this is fixed in a future version

Thanks


Daniel Häfele

unread,
Sep 1, 2015, 4:29:57 AM9/1/15
to RavenDB - 2nd generation document database
This isn't really a bug.
In Json a DateTime is just a string with a specific format, there is no way for RavenDB to know that this is really a string, not a date-time.

Take a look at this discussion, he got into the same issue.

Chris Marisic

unread,
Sep 1, 2015, 11:30:26 AM9/1/15
to RavenDB - 2nd generation document database
Use DateTimes or use myDateTime.Ticks 

Charles Solar

unread,
Sep 1, 2015, 2:40:06 PM9/1/15
to RavenDB - 2nd generation document database
Aha - I knew it had to have been an issue before, but I still argue that it is a bug.

If I store "XYZ" into a field and later search for "XYZ" I should get results - I think everyone can agree to that.  In this situation I understand that this is just JSON so a field is parsed to determine its type dynamically - but there is a solution to this mismatching of terms.  Simply use the same parsing to parse the query parameters too..

If I store "2015-08-31T23:32:00-05:00" it will be stored as 2015-08-31T23:32:000000-05:00 in ravendb having automatically been determined to be a date - so when I query for "2015-08-31T23:32:00-05:00" ravendb should parse this string as well, find that its a datetime, then do a term search for 2015-08-31T23:32:000000-05:00.

But I do see the value of storing dates as ticks instead - so I will continue doing this 

Chris Marisic

unread,
Sep 1, 2015, 4:07:22 PM9/1/15
to RavenDB - 2nd generation document database
This is just an unfortunate ambiguity of JSON when it comes to dates. Time is incredibly difficult and javascript has always been by far the worst of any "modern" language at dealing with it.
Reply all
Reply to author
Forward
0 new messages