@@ -472,19 +472,12 @@ public DateFieldType(String name) {
472472 this (name , true , true , false , true , DEFAULT_DATE_TIME_FORMATTER , Resolution .MILLISECONDS , null , null , Collections .emptyMap ());
473473 }
474474
475+ public DateFieldType (String name , boolean isIndexed , Resolution resolution ) {
476+ this (name , isIndexed , isIndexed , false , true , DEFAULT_DATE_TIME_FORMATTER , resolution , null , null , Collections .emptyMap ());
477+ }
478+
475479 public DateFieldType (String name , boolean isIndexed ) {
476- this (
477- name ,
478- isIndexed ,
479- isIndexed ,
480- false ,
481- true ,
482- DEFAULT_DATE_TIME_FORMATTER ,
483- Resolution .MILLISECONDS ,
484- null ,
485- null ,
486- Collections .emptyMap ()
487- );
480+ this (name , isIndexed , Resolution .MILLISECONDS );
488481 }
489482
490483 public DateFieldType (String name , DateFormatter dateFormatter ) {
@@ -698,6 +691,54 @@ public static long parseToLong(
698691 return resolution .convert (dateParser .parse (BytesRefs .toString (value ), now , roundUp , zone ));
699692 }
700693
694+ /**
695+ * Similar to the {@link DateFieldType#termQuery} method, but works on dates that are already parsed to a long
696+ * in the same precision as the field mapper.
697+ */
698+ public Query equalityQuery (Long value , @ Nullable SearchExecutionContext context ) {
699+ return rangeQuery (value , value , true , true , context );
700+ }
701+
702+ /**
703+ * Similar to the existing
704+ * {@link DateFieldType#rangeQuery(Object, Object, boolean, boolean, ShapeRelation, ZoneId, DateMathParser, SearchExecutionContext)}
705+ * method, but works on dates that are already parsed to a long in the same precision as the field mapper.
706+ */
707+ public Query rangeQuery (
708+ Long lowerTerm ,
709+ Long upperTerm ,
710+ boolean includeLower ,
711+ boolean includeUpper ,
712+ SearchExecutionContext context
713+ ) {
714+ failIfNotIndexedNorDocValuesFallback (context );
715+ long l , u ;
716+ if (lowerTerm == null ) {
717+ l = Long .MIN_VALUE ;
718+ } else {
719+ l = (includeLower == false ) ? lowerTerm + 1 : lowerTerm ;
720+ }
721+ if (upperTerm == null ) {
722+ u = Long .MAX_VALUE ;
723+ } else {
724+ u = (includeUpper == false ) ? upperTerm - 1 : upperTerm ;
725+ }
726+ Query query ;
727+ if (isIndexed ()) {
728+ query = LongPoint .newRangeQuery (name (), l , u );
729+ if (hasDocValues ()) {
730+ Query dvQuery = SortedNumericDocValuesField .newSlowRangeQuery (name (), l , u );
731+ query = new IndexOrDocValuesQuery (query , dvQuery );
732+ }
733+ } else {
734+ query = SortedNumericDocValuesField .newSlowRangeQuery (name (), l , u );
735+ }
736+ if (hasDocValues () && context .indexSortedOnField (name ())) {
737+ query = new XIndexSortSortedNumericDocValuesRangeQuery (name (), l , u , query );
738+ }
739+ return query ;
740+ }
741+
701742 @ Override
702743 public Query distanceFeatureQuery (Object origin , String pivot , SearchExecutionContext context ) {
703744 failIfNotIndexedNorDocValuesFallback (context );
0 commit comments