The DateDiff field expression calculates the difference between two dates and stores the result in a new field. For instance, the following examples compare a document's publication date to an arbitrary date, and then expose the difference as the value of a new field in the document.
Comparisons can be made on any of the following scales (see here ). Note that DAYOFMONTH, DAYOFWEEK, and DAYOFYEAR produce the same result, which is the number of days between the two dates.
QueryRequest request = new QueryRequest("*:*)"); FieldExpression delta = new DateDiff(CalendarField.DAYOFYEAR,new StoredField("date"),"2014-06-10"); delta.setAlias("DATEDIFF"); request.addField(delta); // ... (Perform Search)
DATEDIFF(FUNCTIONNAME,FIELDEXPRESSION,FIELDEXPRESSION) AS ALIAS
- FUNCTIONNAME - any of the available date extraction functions listed above
- FIELDEXPRESSION - Any field expression that evaluates to a date.
- ALIAS - New field name for the result of the function.
&fields=DATEDIFF(DAYOFYEAR,date,"2014-06-10") as "DATEDIFF"