Skip to content

Commit 314762f

Browse files
committed
iter
1 parent 7b00ab9 commit 314762f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.apache.lucene.index.PointValues;
1616
import org.apache.lucene.index.Terms;
1717
import org.apache.lucene.search.FieldComparator;
18-
import org.apache.lucene.search.FieldComparatorSource;
1918
import org.apache.lucene.search.Pruning;
2019
import org.apache.lucene.search.SortField;
2120
import org.elasticsearch.ElasticsearchParseException;
@@ -27,6 +26,7 @@
2726
import org.elasticsearch.common.time.DateMathParser;
2827
import org.elasticsearch.common.time.DateUtils;
2928
import org.elasticsearch.common.util.BigArrays;
29+
import org.elasticsearch.index.IndexMode;
3030
import org.elasticsearch.index.IndexSortConfig;
3131
import org.elasticsearch.index.fielddata.IndexFieldData;
3232
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
@@ -379,12 +379,30 @@ public SortFieldAndFormat build(SearchExecutionContext context) throws IOExcepti
379379
// TODO: HACK to wire up the special timestamp comparator
380380
// (typically we default to Lucene's sort fields and enabling a custom sort field for timestamp field mapper fails,
381381
// because index sorting uses this as well. Index sorting doesn't support custom sort fields. Need to fix this)
382-
if (DataStream.TIMESTAMP_FIELD_NAME.equals(fieldName)) {
383-
field = new SortField(getFieldName(), new FieldComparatorSource() {
382+
var indexMode = context.getIndexSettings().getMode();
383+
if (DataStream.TIMESTAMP_FIELD_NAME.equals(fieldName)
384+
&& (indexMode == IndexMode.LOGSDB || indexMode == IndexMode.TIME_SERIES)) {
385+
field = new SortField(getFieldName(), new IndexFieldData.XFieldComparatorSource(missing, localSortMode(), nested) {
384386
@Override
385387
public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning pruning, boolean reversed) {
386388
return new TimestampComparator(numHits, reversed);
387389
}
390+
391+
@Override
392+
public SortField.Type reducedType() {
393+
return SortField.Type.LONG;
394+
}
395+
396+
@Override
397+
public BucketedSort newBucketedSort(
398+
BigArrays bigArrays,
399+
SortOrder sortOrder,
400+
DocValueFormat format,
401+
int bucketSize,
402+
BucketedSort.ExtraData extra
403+
) {
404+
throw new UnsupportedOperationException("not yet implemented");
405+
}
388406
}, reverse);
389407
} else {
390408
field = fieldData.sortField(missing, localSortMode(), nested, reverse);

0 commit comments

Comments
 (0)