Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedNumericSortField;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down Expand Up @@ -295,7 +295,7 @@ public void rangeQueryWithDocValuesSkipper(final Blackhole bh) throws IOExceptio
/**
* Runs the actual Lucene range query, optionally combining a {@link LongPoint} index query
* with doc values ({@link SortedNumericDocValuesField}) via {@link IndexOrDocValuesQuery},
* and then wrapping it with an {@link IndexSortSortedNumericDocValuesRangeQuery} to utilize the index sort.
* and then wrapping it with an {@link XIndexSortSortedNumericDocValuesRangeQuery} to utilize the index sort.
*
* @param searcher the Lucene {@link IndexSearcher}
* @param rangeStartTimestamp lower bound of the timestamp range
Expand All @@ -316,7 +316,7 @@ private long rangeQuery(final IndexSearcher searcher, long rangeStartTimestamp,
)
: SortedNumericDocValuesField.newSlowRangeQuery(TIMESTAMP_FIELD, rangeStartTimestamp, rangeEndTimestamp);

final Query query = new IndexSortSortedNumericDocValuesRangeQuery(
final Query query = new XIndexSortSortedNumericDocValuesRangeQuery(
TIMESTAMP_FIELD,
rangeStartTimestamp,
rangeEndTimestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.apache.lucene.document.Document;
import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DirectoryReader;
Expand All @@ -31,6 +30,7 @@
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.lucene.document.NumericField;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -48,7 +48,7 @@ public void testTermQuery() {
);
double value = (randomDouble() * 2 - 1) * 10000;
long scaledValue = Math.round(value * ft.getScalingFactor());
assertEquals(LongField.newExactQuery("scaled_float", scaledValue), ft.termQuery(value, MOCK_CONTEXT));
assertEquals(NumericField.newExactLongQuery("scaled_float", scaledValue), ft.termQuery(value, MOCK_CONTEXT));

MappedFieldType ft2 = new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float", 0.1 + randomDouble() * 100, false);
ElasticsearchException e2 = expectThrows(ElasticsearchException.class, () -> ft2.termQuery("42", MOCK_CONTEXT_DISALLOW_EXPENSIVE));
Expand Down
1 change: 1 addition & 0 deletions server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,5 @@
exports org.elasticsearch.plugins.internal.rewriter to org.elasticsearch.inference;
exports org.elasticsearch.lucene.util.automaton;
exports org.elasticsearch.index.codec.perfield;
exports org.elasticsearch.lucene.search;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.lucene.index.PointValues;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.geo.ShapeRelation;
Expand Down Expand Up @@ -50,6 +49,7 @@
import org.elasticsearch.index.query.DateRangeIncludingNowQuery;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
import org.elasticsearch.script.DateFieldScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptCompiler;
Expand Down Expand Up @@ -750,7 +750,7 @@ public Query rangeQuery(
query = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
}
if (hasDocValues() && context.indexSortedOnField(name())) {
query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
query = new XIndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
}
return query;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.sandbox.document.HalfFloatPoint;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
Expand All @@ -47,6 +46,8 @@
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.TimeSeriesParams.MetricType;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.lucene.document.NumericField;
import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
import org.elasticsearch.script.DoubleFieldScript;
import org.elasticsearch.script.LongFieldScript;
import org.elasticsearch.script.Script;
Expand Down Expand Up @@ -1146,7 +1147,7 @@ public Query termQuery(String field, Object value, boolean isIndexed, boolean ha
int v = parse(value, true);

if (isIndexed && hasDocValues) {
return IntField.newExactQuery(field, v);
return NumericField.newExactIntQuery(field, v);
} else if (isIndexed) {
return IntPoint.newExactQuery(field, v);
} else {
Expand Down Expand Up @@ -1223,7 +1224,7 @@ public Query rangeQuery(
query = SortedNumericDocValuesField.newSlowRangeQuery(field, l, u);
}
if (hasDocValues && context.indexSortedOnField(field)) {
query = new IndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
query = new XIndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
}
return query;
}
Expand Down Expand Up @@ -1330,7 +1331,7 @@ public Query termQuery(String field, Object value, boolean isIndexed, boolean ha

long v = parse(value, true);
if (isIndexed && hasDocValues) {
return LongField.newExactQuery(field, v);
return NumericField.newExactLongQuery(field, v);
} else if (isIndexed) {
return LongPoint.newExactQuery(field, v);
} else {
Expand Down Expand Up @@ -1381,7 +1382,7 @@ public Query rangeQuery(
query = SortedNumericDocValuesField.newSlowRangeQuery(field, l, u);
}
if (hasDocValues && context.indexSortedOnField(field)) {
query = new IndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
query = new XIndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
}
return query;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.lucene.document;

import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.PointRangeQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;

public final class NumericField {

private NumericField() {
// Utility class, no instantiation
}

public static Query newExactLongQuery(String field, long value) {
return newRangeLongQuery(field, value, value);
}

public static Query newRangeLongQuery(String field, long lowerValue, long upperValue) {
PointRangeQuery.checkArgs(field, lowerValue, upperValue);
Query fallbackQuery = new IndexOrDocValuesQuery(
LongPoint.newRangeQuery(field, lowerValue, upperValue),
SortedNumericDocValuesField.newSlowRangeQuery(field, lowerValue, upperValue)
);
return new XIndexSortSortedNumericDocValuesRangeQuery(field, lowerValue, upperValue, fallbackQuery);
}

public static Query newExactIntQuery(String field, int value) {
return newRangeIntQuery(field, value, value);
}

public static Query newRangeIntQuery(String field, int lowerValue, int upperValue) {
PointRangeQuery.checkArgs(field, lowerValue, upperValue);
Query fallbackQuery = new IndexOrDocValuesQuery(
IntPoint.newRangeQuery(field, lowerValue, upperValue),
SortedNumericDocValuesField.newSlowRangeQuery(field, lowerValue, upperValue)
);
return new XIndexSortSortedNumericDocValuesRangeQuery(field, lowerValue, upperValue, fallbackQuery);
}

}
Loading