Skip to content

Commit

Permalink
Add support for date fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rayshrey committed Jan 3, 2025
1 parent 6b079da commit 98ef9ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/src/main/java/org/opensearch/index/get/ShardGetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.opensearch.common.lucene.uid.VersionsAndSeqNoResolver.DocIdAndVersion;
import org.opensearch.common.metrics.CounterMetric;
import org.opensearch.common.metrics.MeanMetric;
import org.opensearch.common.time.DateFormatter;
import org.opensearch.common.util.set.Sets;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
Expand All @@ -70,6 +71,7 @@
import org.opensearch.index.fielddata.SortedNumericDoubleValues;
import org.opensearch.index.fieldvisitor.CustomFieldsVisitor;
import org.opensearch.index.fieldvisitor.FieldsVisitor;
import org.opensearch.index.mapper.DateFieldMapper;
import org.opensearch.index.mapper.DocumentMapper;
import org.opensearch.index.mapper.FieldMapper;
import org.opensearch.index.mapper.IdFieldMapper;
Expand Down Expand Up @@ -566,6 +568,20 @@ private static Map<String, Object> buildUsingDocValues(int docId, LeafReader rea
}
}
}
} else if (fieldMapper instanceof DateFieldMapper) {
DateFormatter dateFormatter = ((DateFieldMapper) fieldMapper).fieldType().dateTimeFormatter();
if (sndv.advanceExact(docId)) {
int size = sndv.docValueCount();
String[] vals = new String[size];
for (int i = 0; i < size; i++) {
vals[i] = dateFormatter.formatMillis(sndv.nextValue());
}
if (size > 1) {
docValues.put(fieldName, vals);
} else {
docValues.put(fieldName, vals[0]);
}
}
}
break;
}
Expand Down
16 changes: 16 additions & 0 deletions server/src/main/java/org/opensearch/search/fetch/FetchPhase.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.opensearch.common.document.DocumentField;
import org.opensearch.common.lucene.index.SequentialStoredFieldsLeafReader;
import org.opensearch.common.lucene.search.Queries;
import org.opensearch.common.time.DateFormatter;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
Expand All @@ -68,6 +69,7 @@
import org.opensearch.index.fielddata.SortedNumericDoubleValues;
import org.opensearch.index.fieldvisitor.CustomFieldsVisitor;
import org.opensearch.index.fieldvisitor.FieldsVisitor;
import org.opensearch.index.mapper.DateFieldMapper;
import org.opensearch.index.mapper.DocumentMapper;
import org.opensearch.index.mapper.FieldMapper;
import org.opensearch.index.mapper.MappedFieldType;
Expand Down Expand Up @@ -488,6 +490,20 @@ private static Map<String, Object> buildUsingDocValues(int docId, LeafReader rea
}
}
}
} else if (fieldMapper instanceof DateFieldMapper) {
DateFormatter dateFormatter = ((DateFieldMapper) fieldMapper).fieldType().dateTimeFormatter();
if (sndv.advanceExact(docId)) {
int size = sndv.docValueCount();
String[] vals = new String[size];
for (int i = 0; i < size; i++) {
vals[i] = dateFormatter.formatMillis(sndv.nextValue());
}
if (size > 1) {
docValues.put(fieldName, vals);
} else {
docValues.put(fieldName, vals[0]);
}
}
}
break;
}
Expand Down

0 comments on commit 98ef9ef

Please sign in to comment.