I am trying to perform a simple Date query on Google App Engine using the Search API. All I am trying to achieve is to obtain a list of all Documents that have a Field equal to a certain Date...
// Prepare the Query
String searchString = "date = 2013-08-26";
Query query = Query.newBuilder().build(searchString);
// Get the Date_Search Index
IndexSpec indexSpec = IndexSpec.newBuilder().setName("Date_Search").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
// Perform the search
Results<ScoredDocument> results = index.search(query);
When I run the above code, no results are returned. However, if I change the query to be date >= 2013-08-26 && date < 2013-08-27
instead, the expected results are returned. It seems as though the date equality logic isn't working.
This is the list of Documents in my Index...
DocId OrderId date event_key
3d4e5691-8fb9-42de-bf09-f2303236f091 84288787 2013-08-25 641.0
7e4700fe-dee1-4579-87c5-69b1b1929f39 84288787 2013-08-25 650.0
8c9ca43d-7673-4f12-9f0b-e3328cbdaa85 84288787 2013-08-26 659.0
04fa8025-e01b-42d3-9bf9-21c3d9618ca7 84288787 2013-08-26 668.0
41465d1f-6d8a-431f-b226-141c8d72c064 84288787 2013-08-26 676.0
1ba01a6b-0890-43b3-8225-0ed196b6ee80 84288787 2013-08-27 676.0
a8ef18b1-ffa5-4823-8442-852f7142cad1 84288786 2013-08-25 633.0
I would be expecting that 3 documents would be returned for the date 2013-08-26. When running with the equality date = 2013-08-26
there are no results, but the query date >= 2013-08-26 && date < 2013-08-27
returns the expected 3 results.
The Documents were added to the Index using the following code...
// Build the Date
Calendar calendar = Calendar.getInstance();
Date dateObject = calendar.getTime();
// Create the Document
Builder builder = Document.newBuilder();
builder.addField(Field.newBuilder().setName("event_key").setNumber(eventKey));
builder.addField(Field.newBuilder().setName("date").setDate(dateObject));
Document document = builder.build();
// Get the Date_Search Index
IndexSpec indexSpec = IndexSpec.newBuilder().setName("Date_Search").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
// Store the Document
index.put(document);
According to the Search API Documentation, Date fields are stored and are query-able only to YYYY-MM-DD precision(the Time information is stripped out when storing and querying). Additionally, the Query on Date Fields Documentation shows that date equality queries are supported.
Could someone please help me to understand what the issue is.
This issue has been resolved in SDK 1.8.4.
Please take note that upgrading to 1.8.4 caused my development datastore to become invalid, as Google are allowed to do if required. Once I recreated the data in the 1.8.4 datastore, the Search API worked correctly for the equality Date Search.