ソースを参照

[8.19] Upgrade to lucene 9.12.2 (#129555)

This commit upgrades to 9.12.2.

With the release of 10.2.2, we no longer need to workaround the Lucene bug mentioned in 128671.
Chris Hegarty 3 ヶ月 前
コミット
218d4a88b6

+ 0 - 7
build-tools-internal/src/main/resources/forbidden/es-all-signatures.txt

@@ -61,10 +61,3 @@ org.apache.logging.log4j.message.ParameterizedMessage#<init>(java.lang.String, j
 
 @defaultMessage Use WriteLoadForecaster#getForecastedWriteLoad instead
 org.elasticsearch.cluster.metadata.IndexMetadata#getForecastedWriteLoad()
-
-# This is a temporary patch as there is a low level Lucene bug in certain scenarios
-org.apache.lucene.document.LongField#newExactQuery(java.lang.String, long) @ Use org.elasticsearch.lucene.document.NumericField#newExactLongQuery(java.lang.String, long) instead.
-org.apache.lucene.document.LongField#newRangeQuery(java.lang.String, long, long) @ Use org.elasticsearch.lucene.document.NumericField#newRangeLongQuery(java.lang.String, long, long) instead.
-org.apache.lucene.document.IntField#newExactQuery(java.lang.String, int) @ Use org.elasticsearch.lucene.document.NumericField#newExactIntQuery(java.lang.String, int) instead.
-org.apache.lucene.document.IntField#newRangeQuery(java.lang.String, int, int) @ Use org.elasticsearch.lucene.document.NumericField#newRangeIntQuery(java.lang.String, int, int) instead.
-org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery @ use org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery instead.

+ 1 - 1
build-tools-internal/version.properties

@@ -1,5 +1,5 @@
 elasticsearch     = 8.19.0
-lucene            = 9.12.1
+lucene            = 9.12.2
 
 bundled_jdk_vendor = openjdk
 bundled_jdk = 24+36@1f9ff9062db4449d8ca828c504ffae90

+ 2 - 2
docs/Versions.asciidoc

@@ -1,8 +1,8 @@
 
 include::{docs-root}/shared/versions/stack/{source_branch}.asciidoc[]
 
-:lucene_version:        9.12.1
-:lucene_version_path:   9_12_1
+:lucene_version:        9.12.2
+:lucene_version_path:   9_12_2
 :jdk:                   11.0.2
 :jdk_major:             11
 :build_type:            tar

+ 14 - 0
docs/changelog/129555.yaml

@@ -0,0 +1,14 @@
+pr: 129555
+summary: "[8.19] Upgrade to lucene 9.12.2"
+area: Search
+type: upgrade
+issues: []
+highlight:
+  title: Upgrade to lucene 9.12.2
+  body: |-
+    * Reduce NeighborArray on-heap memory during HNSW graph building
+    * Fix IndexSortSortedNumericDocValuesRangeQuery for integer sorting
+    * ValueSource.fromDoubleValuesSource(dvs).getSortField() would throw errors when used if the DoubleValuesSource needed scores
+    * Disable connectedComponents logic in HNSW graph building.
+    ----
+  notable: true

+ 75 - 75
gradle/verification-metadata.xml

@@ -2998,129 +2998,129 @@
             <sha256 value="015d5c229f3cd5c0ebf175c1da08d596d94043362ae9d92637d88848c90537c8" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-common" version="9.12.1">
-         <artifact name="lucene-analysis-common-9.12.1.jar">
-            <sha256 value="0e7534d4b6e1c3ce7af939028b3e8c1730ffb29ea5d689de2bc166c482e01b5d" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-common" version="9.12.2">
+         <artifact name="lucene-analysis-common-9.12.2.jar">
+            <sha256 value="a472f61b4d7738787bf1a637beac0ebf134d785c37aa069fb071e9715568c8b8" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-icu" version="9.12.1">
-         <artifact name="lucene-analysis-icu-9.12.1.jar">
-            <sha256 value="27dc3353be141e9ae7ed236aeb44b5e7ff35dda45555fcbdd5d8aefb7149ab16" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-icu" version="9.12.2">
+         <artifact name="lucene-analysis-icu-9.12.2.jar">
+            <sha256 value="4cb8039065c433d50095daf7a2ef2c39c3800d67b1520dfd8ff63688fc215f68" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-kuromoji" version="9.12.1">
-         <artifact name="lucene-analysis-kuromoji-9.12.1.jar">
-            <sha256 value="c035ed289413071e88f64d8bac1eba2b9ac6f382e7d1684fedf3b822f23a6495" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-kuromoji" version="9.12.2">
+         <artifact name="lucene-analysis-kuromoji-9.12.2.jar">
+            <sha256 value="0aa57815282705ad1926f92d25202fb1beb1b6beb034b527f63efb687a506996" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-morfologik" version="9.12.1">
-         <artifact name="lucene-analysis-morfologik-9.12.1.jar">
-            <sha256 value="6fac575c1f91b409ff82bf7d18883d0b90dc59f0b321f07036b23ed8df336663" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-morfologik" version="9.12.2">
+         <artifact name="lucene-analysis-morfologik-9.12.2.jar">
+            <sha256 value="0d60093a224ab41474786a664395541b38cbc48b504e982db7bb3388b68311c9" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-nori" version="9.12.1">
-         <artifact name="lucene-analysis-nori-9.12.1.jar">
-            <sha256 value="6fd6b9661a1fa1feae6c6a0d82ae8cb4e661bcb8ba1a35693ae80e4571afe5c3" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-nori" version="9.12.2">
+         <artifact name="lucene-analysis-nori-9.12.2.jar">
+            <sha256 value="74df2f9ba8dcc94ad27e3bbfb862e3596abcfae2e68ced3858f67f2499fbdec1" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-phonetic" version="9.12.1">
-         <artifact name="lucene-analysis-phonetic-9.12.1.jar">
-            <sha256 value="d98e2d1f6c3ef9567fe6ea6eaee339653491fda100d8df546894f2368ecfdb52" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-phonetic" version="9.12.2">
+         <artifact name="lucene-analysis-phonetic-9.12.2.jar">
+            <sha256 value="68fb35fc18290e5bc807c9b24dddc8bfcabfcb668ab28db4d0687d6add837d29" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-smartcn" version="9.12.1">
-         <artifact name="lucene-analysis-smartcn-9.12.1.jar">
-            <sha256 value="c06f28b6c5e7ce77fb66ed64471683a4a2591d883415895fde36b178d692ac88" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-smartcn" version="9.12.2">
+         <artifact name="lucene-analysis-smartcn-9.12.2.jar">
+            <sha256 value="30b4bf85ad0f27f9c5c49e3cd1b3cbcd923f24b8a722f462e5f3e96dba9568c4" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-analysis-stempel" version="9.12.1">
-         <artifact name="lucene-analysis-stempel-9.12.1.jar">
-            <sha256 value="9c3078761888f091a81cbc9191685f4d3a05a4aff83991ec832cfd8bb244a42a" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-analysis-stempel" version="9.12.2">
+         <artifact name="lucene-analysis-stempel-9.12.2.jar">
+            <sha256 value="8c1c101b7fcdf48432cf409317ec58753182c2947aa34c0de7ab419ba16746c3" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-backward-codecs" version="9.12.1">
-         <artifact name="lucene-backward-codecs-9.12.1.jar">
-            <sha256 value="9255caa35fe9f29e97a39935118204479efde22bb23bafcd2859e296f4571792" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-backward-codecs" version="9.12.2">
+         <artifact name="lucene-backward-codecs-9.12.2.jar">
+            <sha256 value="4a027b24ab6213402c4af76aeae7344771548743822880aec09817e76a4690e9" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-codecs" version="9.12.1">
-         <artifact name="lucene-codecs-9.12.1.jar">
-            <sha256 value="a1807c8351d8c53828e588cc586dbc4b6635341cd7ae401f18b5ac883821aaf0" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-codecs" version="9.12.2">
+         <artifact name="lucene-codecs-9.12.2.jar">
+            <sha256 value="ee055269f7e3934f2c0577c7417bafc65d9c08dda31061634be68519606409f8" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-core" version="9.12.1">
-         <artifact name="lucene-core-9.12.1.jar">
-            <sha256 value="8d812e9fa6dbd816808205e6cb4d7ab43a747e379c8cb31a0d6dc91050b3f97a" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-core" version="9.12.2">
+         <artifact name="lucene-core-9.12.2.jar">
+            <sha256 value="3a5426c7082a16adfe39a55502eecf4e69547e62d3dcf292c730e228fbaad2fd" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-expressions" version="9.12.1">
-         <artifact name="lucene-expressions-9.12.1.jar">
-            <sha256 value="7fb06e21ff3fefda6a481c70f84e489670e4fec52c58d4d082103b73c6be93d3" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-expressions" version="9.12.2">
+         <artifact name="lucene-expressions-9.12.2.jar">
+            <sha256 value="193c70854a83abe16ed8ea3d33a6f4b15fd302f6f539621ace13c8b253bc02e1" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-facet" version="9.12.1">
-         <artifact name="lucene-facet-9.12.1.jar">
-            <sha256 value="36910f094d21907908c65eaab6f892ef1aa11081612c652b6bfafddc7b0b1ef1" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-facet" version="9.12.2">
+         <artifact name="lucene-facet-9.12.2.jar">
+            <sha256 value="02c9ac783dda2914f6f62689314bad0efc1d3ee3c630f5c9bb357d736f1cc9ff" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-grouping" version="9.12.1">
-         <artifact name="lucene-grouping-9.12.1.jar">
-            <sha256 value="b6a93845493a275e66c776e9d567109c13b68de81cb3de067ec99637bad5551e" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-grouping" version="9.12.2">
+         <artifact name="lucene-grouping-9.12.2.jar">
+            <sha256 value="d3255d0279e1a41cf145f3d01019dda6ba9d7e2d3185f4170570072baf8e95ca" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-highlighter" version="9.12.1">
-         <artifact name="lucene-highlighter-9.12.1.jar">
-            <sha256 value="f8a4184b7b1cd490a7161887f2984856ff7de39ec2394073f884bcabccb45d69" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-highlighter" version="9.12.2">
+         <artifact name="lucene-highlighter-9.12.2.jar">
+            <sha256 value="e0ce89f860e7e450ac08500c40f2b7a221b161610d12df9f50a6a49b2547863a" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-join" version="9.12.1">
-         <artifact name="lucene-join-9.12.1.jar">
-            <sha256 value="e53ebf2d59c8f482ab14af07bb41ba2d3617000f7781768b7fe53b1d0e2249b0" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-join" version="9.12.2">
+         <artifact name="lucene-join-9.12.2.jar">
+            <sha256 value="94d5fa2fd7e0f7e0711717b3e23bb148a5a356270c5e6cda720070a4d092276e" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-memory" version="9.12.1">
-         <artifact name="lucene-memory-9.12.1.jar">
-            <sha256 value="587363f98e410549fa5b2028b355d329231607f992303234ca1866311d9d7d29" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-memory" version="9.12.2">
+         <artifact name="lucene-memory-9.12.2.jar">
+            <sha256 value="6222e7d436c380652e51bc4c4c27a8a56c7f9e70d7aa0fad07a76b85bd52dcb2" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-misc" version="9.12.1">
-         <artifact name="lucene-misc-9.12.1.jar">
-            <sha256 value="0d5c9476758191a3e4c07db977a9cdc56dba3cfac026ee79d03756e81a17e16a" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-misc" version="9.12.2">
+         <artifact name="lucene-misc-9.12.2.jar">
+            <sha256 value="20eaded0c0b6141aed36359a551bad300eb8b5264b904110de7d845bad858df1" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-queries" version="9.12.1">
-         <artifact name="lucene-queries-9.12.1.jar">
-            <sha256 value="3630f4d53203d62152cdb993a7b4f9d4e52cff2688ba549ad09cc01d5d78b5f8" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-queries" version="9.12.2">
+         <artifact name="lucene-queries-9.12.2.jar">
+            <sha256 value="8c07692e0acacd7433f14107296e9d3402d6d435d4c4ed2aa6412e9b90d3d6b4" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-queryparser" version="9.12.1">
-         <artifact name="lucene-queryparser-9.12.1.jar">
-            <sha256 value="9746eb991203553ade09491ac49415e3711ec32e4ad3cd705d8d9620a32192dd" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-queryparser" version="9.12.2">
+         <artifact name="lucene-queryparser-9.12.2.jar">
+            <sha256 value="dc80ae71863446b5251e93ec258ba959aecb44f0800623947262860e8efff4d0" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-sandbox" version="9.12.1">
-         <artifact name="lucene-sandbox-9.12.1.jar">
-            <sha256 value="9aa00ce942216d513352dae89cf8588c6bdd379f82a5d8a30d8652535bd58aae" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-sandbox" version="9.12.2">
+         <artifact name="lucene-sandbox-9.12.2.jar">
+            <sha256 value="f44f1f534709f2b70ef9f12bfe090f97801f88be84d2edc3c18495f0c761978d" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-spatial-extras" version="9.12.1">
-         <artifact name="lucene-spatial-extras-9.12.1.jar">
-            <sha256 value="d9d180a559147e20ed0c1f27bc4e0daf4518b46fce19829eb397c0f07b06f54a" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-spatial-extras" version="9.12.2">
+         <artifact name="lucene-spatial-extras-9.12.2.jar">
+            <sha256 value="16cfd9f14eef7a97d8549f6de5761213053f28079d859228e5d65b4a20a4ffc3" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-spatial3d" version="9.12.1">
-         <artifact name="lucene-spatial3d-9.12.1.jar">
-            <sha256 value="920d541ee609bc36b7f999761a3055622fa08631445616825a0c1ce2d72857cf" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-spatial3d" version="9.12.2">
+         <artifact name="lucene-spatial3d-9.12.2.jar">
+            <sha256 value="b3d649a9c328418e195d82bc63301e6e0c8c702308b74a57ef630d6f8e5899d9" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-suggest" version="9.12.1">
-         <artifact name="lucene-suggest-9.12.1.jar">
-            <sha256 value="6894de92b80e294a07041447caa5bb13d5dee33fe6ff05270afc3e0d1be40140" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-suggest" version="9.12.2">
+         <artifact name="lucene-suggest-9.12.2.jar">
+            <sha256 value="fab3ef755412d4563c79771264d28202f2a900d3bb826667d9eea48d01bf3822" origin="Generated by Gradle"/>
          </artifact>
       </component>
-      <component group="org.apache.lucene" name="lucene-test-framework" version="9.12.1">
-         <artifact name="lucene-test-framework-9.12.1.jar">
-            <sha256 value="62a906edd2648bc173ba86301257d8490af71b986f0abe2323cd0e596402cce1" origin="Generated by Gradle"/>
+      <component group="org.apache.lucene" name="lucene-test-framework" version="9.12.2">
+         <artifact name="lucene-test-framework-9.12.2.jar">
+            <sha256 value="ed3e2df9ddff24411cac5ba264e53f02dcbfa426f9428a3ae8da2e667bd1d18f" origin="Generated by Gradle"/>
          </artifact>
       </component>
       <component group="org.apache.maven" name="maven-api-meta" version="4.0.0-alpha-9">

+ 0 - 1
server/src/main/java/module-info.java

@@ -479,5 +479,4 @@ module org.elasticsearch.server {
     exports org.elasticsearch.monitor.metrics;
     exports org.elasticsearch.plugins.internal.rewriter to org.elasticsearch.inference;
     exports org.elasticsearch.index.codec.perfield;
-    exports org.elasticsearch.lucene.search;
 }

+ 2 - 0
server/src/main/java/org/elasticsearch/index/IndexVersions.java

@@ -134,6 +134,8 @@ public class IndexVersions {
     public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X = def(8_531_0_00, Version.LUCENE_9_12_1);
     public static final IndexVersion INDEX_INT_SORT_INT_TYPE_8_19 = def(8_532_0_00, Version.LUCENE_9_12_1);
     public static final IndexVersion MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED_8_19 = def(8_533_0_00, Version.LUCENE_9_12_1);
+    public static final IndexVersion UPGRADE_TO_LUCENE_9_12_2 = def(8_534_0_00, Version.LUCENE_9_12_2);
+
     /*
      * STOP! READ THIS FIRST! No, really,
      *        ____ _____ ___  ____  _        ____  _____    _    ____    _____ _   _ ___ ____    _____ ___ ____  ____ _____ _

+ 3 - 3
server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

@@ -20,6 +20,7 @@ import org.apache.lucene.index.LeafReaderContext;
 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;
@@ -44,7 +45,6 @@ import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
 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;
@@ -678,7 +678,7 @@ public final class DateFieldMapper extends FieldMapper {
                     query = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
                 }
                 if (hasDocValues() && context.indexSortedOnField(name())) {
-                    query = new XIndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
+                    query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
                 }
                 return query;
             });
@@ -792,7 +792,7 @@ public final class DateFieldMapper extends FieldMapper {
                 query = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
             }
             if (hasDocValues() && context.indexSortedOnField(name())) {
-                query = new XIndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
+                query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
             }
             return query;
         }

+ 3 - 3
server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java

@@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexableField;
 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;
@@ -45,7 +46,6 @@ import org.elasticsearch.index.fielddata.plain.SortedDoublesIndexFieldData;
 import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
 import org.elasticsearch.index.mapper.TimeSeriesParams.MetricType;
 import org.elasticsearch.index.query.SearchExecutionContext;
-import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
 import org.elasticsearch.script.DoubleFieldScript;
 import org.elasticsearch.script.LongFieldScript;
 import org.elasticsearch.script.Script;
@@ -1212,7 +1212,7 @@ public class NumberFieldMapper extends FieldMapper {
                     query = SortedNumericDocValuesField.newSlowRangeQuery(field, l, u);
                 }
                 if (hasDocValues && context.indexSortedOnField(field)) {
-                    query = new XIndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
+                    query = new IndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
                 }
                 return query;
             }
@@ -1368,7 +1368,7 @@ public class NumberFieldMapper extends FieldMapper {
                         query = SortedNumericDocValuesField.newSlowRangeQuery(field, l, u);
                     }
                     if (hasDocValues && context.indexSortedOnField(field)) {
-                        query = new XIndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
+                        query = new IndexSortSortedNumericDocValuesRangeQuery(field, l, u, query);
                     }
                     return query;
                 });

+ 0 - 52
server/src/main/java/org/elasticsearch/lucene/document/NumericField.java

@@ -1,52 +0,0 @@
-/*
- * 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);
-    }
-
-}

+ 0 - 678
server/src/main/java/org/elasticsearch/lucene/search/XIndexSortSortedNumericDocValuesRangeQuery.java

@@ -1,678 +0,0 @@
-/*
- * @notice
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * Modifications copyright (C) 2025 Elasticsearch B.V.
- */
-
-package org.elasticsearch.lucene.search;
-
-import org.apache.lucene.document.IntPoint;
-import org.apache.lucene.document.LongPoint;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReader;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.lucene.index.PointValues;
-import org.apache.lucene.index.PointValues.IntersectVisitor;
-import org.apache.lucene.index.PointValues.PointTree;
-import org.apache.lucene.index.PointValues.Relation;
-import org.apache.lucene.index.SortedNumericDocValues;
-import org.apache.lucene.search.ConstantScoreScorer;
-import org.apache.lucene.search.ConstantScoreWeight;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.FieldComparator;
-import org.apache.lucene.search.FieldExistsQuery;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.LeafFieldComparator;
-import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.Pruning;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.QueryVisitor;
-import org.apache.lucene.search.ScoreMode;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.ScorerSupplier;
-import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.SortField.Type;
-import org.apache.lucene.search.SortedNumericSortField;
-import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.ArrayUtil.ByteArrayComparator;
-
-import java.io.IOException;
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.Objects;
-
-/**
- * copied from Lucene
- */
-public class XIndexSortSortedNumericDocValuesRangeQuery extends Query {
-
-    private final String field;
-    private final long lowerValue;
-    private final long upperValue;
-    private final Query fallbackQuery;
-
-    /**
-     * Creates a new {@link XIndexSortSortedNumericDocValuesRangeQuery}.
-     *
-     * @param field The field name.
-     * @param lowerValue The lower end of the range (inclusive).
-     * @param upperValue The upper end of the range (exclusive).
-     * @param fallbackQuery A query to fall back to if the optimization cannot be applied.
-     */
-    public XIndexSortSortedNumericDocValuesRangeQuery(String field, long lowerValue, long upperValue, Query fallbackQuery) {
-        this.field = Objects.requireNonNull(field);
-        this.lowerValue = lowerValue;
-        this.upperValue = upperValue;
-        this.fallbackQuery = fallbackQuery;
-    }
-
-    public Query getFallbackQuery() {
-        return fallbackQuery;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        XIndexSortSortedNumericDocValuesRangeQuery that = (XIndexSortSortedNumericDocValuesRangeQuery) o;
-        return lowerValue == that.lowerValue
-            && upperValue == that.upperValue
-            && Objects.equals(field, that.field)
-            && Objects.equals(fallbackQuery, that.fallbackQuery);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(field, lowerValue, upperValue, fallbackQuery);
-    }
-
-    @Override
-    public void visit(QueryVisitor visitor) {
-        if (visitor.acceptField(field)) {
-            visitor.visitLeaf(this);
-            fallbackQuery.visit(visitor);
-        }
-    }
-
-    @Override
-    public String toString(String field) {
-        StringBuilder b = new StringBuilder();
-        if (this.field.equals(field) == false) {
-            b.append(this.field).append(":");
-        }
-        return b.append("[").append(lowerValue).append(" TO ").append(upperValue).append("]").toString();
-    }
-
-    @Override
-    public Query rewrite(IndexSearcher indexSearcher) throws IOException {
-        if (lowerValue == Long.MIN_VALUE && upperValue == Long.MAX_VALUE) {
-            return new FieldExistsQuery(field);
-        }
-
-        Query rewrittenFallback = fallbackQuery.rewrite(indexSearcher);
-        if (rewrittenFallback.getClass() == MatchAllDocsQuery.class) {
-            return new MatchAllDocsQuery();
-        }
-        if (rewrittenFallback == fallbackQuery) {
-            return this;
-        } else {
-            return new XIndexSortSortedNumericDocValuesRangeQuery(field, lowerValue, upperValue, rewrittenFallback);
-        }
-    }
-
-    @Override
-    public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
-        Weight fallbackWeight = fallbackQuery.createWeight(searcher, scoreMode, boost);
-
-        return new ConstantScoreWeight(this, boost) {
-
-            @Override
-            public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
-                final Weight weight = this;
-                IteratorAndCount itAndCount = getDocIdSetIteratorOrNull(context);
-                if (itAndCount != null) {
-                    DocIdSetIterator disi = itAndCount.it;
-                    return new ScorerSupplier() {
-                        @Override
-                        public Scorer get(long leadCost) throws IOException {
-                            return new ConstantScoreScorer(weight, score(), scoreMode, disi);
-                        }
-
-                        @Override
-                        public long cost() {
-                            return disi.cost();
-                        }
-                    };
-                }
-                return fallbackWeight.scorerSupplier(context);
-            }
-
-            @Override
-            public Scorer scorer(LeafReaderContext context) throws IOException {
-                ScorerSupplier scorerSupplier = scorerSupplier(context);
-                if (scorerSupplier == null) {
-                    return null;
-                }
-                return scorerSupplier.get(Long.MAX_VALUE);
-            }
-
-            @Override
-            public boolean isCacheable(LeafReaderContext ctx) {
-                // Both queries should always return the same values, so we can just check
-                // if the fallback query is cacheable.
-                return fallbackWeight.isCacheable(ctx);
-            }
-
-            @Override
-            public int count(LeafReaderContext context) throws IOException {
-                if (context.reader().hasDeletions() == false) {
-                    IteratorAndCount itAndCount = getDocIdSetIteratorOrNull(context);
-                    if (itAndCount != null && itAndCount.count != -1) {
-                        return itAndCount.count;
-                    }
-                }
-                return fallbackWeight.count(context);
-            }
-        };
-    }
-
-    private static class ValueAndDoc {
-        byte[] value;
-        int docID;
-        boolean done;
-    }
-
-    /**
-     * Move to the minimum leaf node that has at least one value that is greater than (or equal to if
-     * {@code allowEqual}) {@code value}, and return the next greater value on this block. Upon
-     * returning, the {@code pointTree} must be on the leaf node where the value was found.
-     */
-    private static ValueAndDoc findNextValue(
-        PointTree pointTree,
-        byte[] value,
-        boolean allowEqual,
-        ByteArrayComparator comparator,
-        boolean lastDoc
-    ) throws IOException {
-        int cmp = comparator.compare(pointTree.getMaxPackedValue(), 0, value, 0);
-        if (cmp < 0 || (cmp == 0 && allowEqual == false)) {
-            return null;
-        }
-        if (pointTree.moveToChild() == false) {
-            ValueAndDoc vd = new ValueAndDoc();
-            pointTree.visitDocValues(new IntersectVisitor() {
-
-                @Override
-                public void visit(int docID, byte[] packedValue) throws IOException {
-                    if (vd.value == null) {
-                        int cmp = comparator.compare(packedValue, 0, value, 0);
-                        if (cmp > 0 || (cmp == 0 && allowEqual)) {
-                            vd.value = packedValue.clone();
-                            vd.docID = docID;
-                        }
-                    } else if (lastDoc && vd.done == false) {
-                        int cmp = comparator.compare(packedValue, 0, vd.value, 0);
-                        assert cmp >= 0;
-                        if (cmp > 0) {
-                            vd.done = true;
-                        } else {
-                            vd.docID = docID;
-                        }
-                    }
-                }
-
-                @Override
-                public void visit(int docID) throws IOException {
-                    throw new UnsupportedOperationException();
-                }
-
-                @Override
-                public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
-                    return Relation.CELL_CROSSES_QUERY;
-                }
-            });
-            if (vd.value != null) {
-                return vd;
-            } else {
-                return null;
-            }
-        }
-
-        // Recurse
-        do {
-            ValueAndDoc vd = findNextValue(pointTree, value, allowEqual, comparator, lastDoc);
-            if (vd != null) {
-                return vd;
-            }
-        } while (pointTree.moveToSibling());
-
-        boolean moved = pointTree.moveToParent();
-        assert moved;
-        return null;
-    }
-
-    /**
-     * Find the next value that is greater than (or equal to if {@code allowEqual}) and return either
-     * its first doc ID or last doc ID depending on {@code lastDoc}. This method returns -1 if there
-     * is no greater value in the dataset.
-     */
-    private static int nextDoc(PointTree pointTree, byte[] value, boolean allowEqual, ByteArrayComparator comparator, boolean lastDoc)
-        throws IOException {
-        ValueAndDoc vd = findNextValue(pointTree, value, allowEqual, comparator, lastDoc);
-        if (vd == null) {
-            return -1;
-        }
-        if (lastDoc == false || vd.done) {
-            return vd.docID;
-        }
-
-        // We found the next value, now we need the last doc ID.
-        int doc = lastDoc(pointTree, vd.value, comparator);
-        if (doc == -1) {
-            // vd.docID was actually the last doc ID
-            return vd.docID;
-        } else {
-            return doc;
-        }
-    }
-
-    /**
-     * Compute the last doc ID that matches the given value and is stored on a leaf node that compares
-     * greater than the current leaf node that the provided {@link PointTree} is positioned on. This
-     * returns -1 if no other leaf node contains the provided {@code value}.
-     */
-    private static int lastDoc(PointTree pointTree, byte[] value, ByteArrayComparator comparator) throws IOException {
-        // Create a stack of nodes that may contain value that we'll use to search for the last leaf
-        // node that contains `value`.
-        // While the logic looks a bit complicated due to the fact that the PointTree API doesn't allow
-        // moving back to previous siblings, this effectively performs a binary search.
-        Deque<PointTree> stack = new ArrayDeque<>();
-
-        outer: while (true) {
-
-            // Move to the next node
-            while (pointTree.moveToSibling() == false) {
-                if (pointTree.moveToParent() == false) {
-                    // No next node
-                    break outer;
-                }
-            }
-
-            int cmp = comparator.compare(pointTree.getMinPackedValue(), 0, value, 0);
-            if (cmp > 0) {
-                // This node doesn't have `value`, so next nodes can't either
-                break;
-            }
-
-            stack.push(pointTree.clone());
-        }
-
-        while (stack.isEmpty() == false) {
-            PointTree next = stack.pop();
-            if (next.moveToChild() == false) {
-                int[] lastDoc = { -1 };
-                next.visitDocValues(new IntersectVisitor() {
-
-                    @Override
-                    public void visit(int docID) throws IOException {
-                        throw new UnsupportedOperationException();
-                    }
-
-                    @Override
-                    public void visit(int docID, byte[] packedValue) throws IOException {
-                        int cmp = comparator.compare(value, 0, packedValue, 0);
-                        if (cmp == 0) {
-                            lastDoc[0] = docID;
-                        }
-                    }
-
-                    @Override
-                    public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
-                        return Relation.CELL_CROSSES_QUERY;
-                    }
-                });
-                if (lastDoc[0] != -1) {
-                    return lastDoc[0];
-                }
-            } else {
-                do {
-                    int cmp = comparator.compare(next.getMinPackedValue(), 0, value, 0);
-                    if (cmp > 0) {
-                        // This node doesn't have `value`, so next nodes can't either
-                        break;
-                    }
-                    stack.push(next.clone());
-                } while (next.moveToSibling());
-            }
-        }
-
-        return -1;
-    }
-
-    private boolean matchNone(PointValues points, byte[] queryLowerPoint, byte[] queryUpperPoint) throws IOException {
-        assert points.getNumDimensions() == 1;
-        final ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(points.getBytesPerDimension());
-        return comparator.compare(points.getMinPackedValue(), 0, queryUpperPoint, 0) > 0
-            || comparator.compare(points.getMaxPackedValue(), 0, queryLowerPoint, 0) < 0;
-    }
-
-    private boolean matchAll(PointValues points, byte[] queryLowerPoint, byte[] queryUpperPoint) throws IOException {
-        assert points.getNumDimensions() == 1;
-        final ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(points.getBytesPerDimension());
-        return comparator.compare(points.getMinPackedValue(), 0, queryLowerPoint, 0) >= 0
-            && comparator.compare(points.getMaxPackedValue(), 0, queryUpperPoint, 0) <= 0;
-    }
-
-    private IteratorAndCount getDocIdSetIteratorOrNullFromBkd(LeafReaderContext context, DocIdSetIterator delegate) throws IOException {
-        Sort indexSort = context.reader().getMetaData().getSort();
-        if (indexSort == null || indexSort.getSort().length == 0 || indexSort.getSort()[0].getField().equals(field) == false) {
-            return null;
-        }
-
-        final boolean reverse = indexSort.getSort()[0].getReverse();
-
-        PointValues points = context.reader().getPointValues(field);
-        if (points == null) {
-            return null;
-        }
-
-        if (points.getNumDimensions() != 1) {
-            return null;
-        }
-
-        if (points.getBytesPerDimension() != Long.BYTES && points.getBytesPerDimension() != Integer.BYTES) {
-            return null;
-        }
-
-        if (points.size() != points.getDocCount()) {
-            return null;
-        }
-
-        assert lowerValue <= upperValue;
-        byte[] queryLowerPoint;
-        byte[] queryUpperPoint;
-        if (points.getBytesPerDimension() == Integer.BYTES) {
-            queryLowerPoint = IntPoint.pack((int) lowerValue).bytes;
-            queryUpperPoint = IntPoint.pack((int) upperValue).bytes;
-        } else {
-            queryLowerPoint = LongPoint.pack(lowerValue).bytes;
-            queryUpperPoint = LongPoint.pack(upperValue).bytes;
-        }
-        if (matchNone(points, queryLowerPoint, queryUpperPoint)) {
-            return IteratorAndCount.empty();
-        }
-        if (matchAll(points, queryLowerPoint, queryUpperPoint)) {
-            int maxDoc = context.reader().maxDoc();
-            if (points.getDocCount() == maxDoc) {
-                return IteratorAndCount.all(maxDoc);
-            } else {
-                return IteratorAndCount.sparseRange(0, maxDoc, delegate);
-            }
-        }
-
-        int minDocId, maxDocId;
-        final ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(points.getBytesPerDimension());
-
-        if (reverse) {
-            minDocId = nextDoc(points.getPointTree(), queryUpperPoint, false, comparator, true) + 1;
-        } else {
-            minDocId = nextDoc(points.getPointTree(), queryLowerPoint, true, comparator, false);
-            if (minDocId == -1) {
-                // No matches
-                return IteratorAndCount.empty();
-            }
-        }
-
-        if (reverse) {
-            maxDocId = nextDoc(points.getPointTree(), queryLowerPoint, true, comparator, true) + 1;
-            if (maxDocId == 0) {
-                // No matches
-                return IteratorAndCount.empty();
-            }
-        } else {
-            maxDocId = nextDoc(points.getPointTree(), queryUpperPoint, false, comparator, false);
-            if (maxDocId == -1) {
-                maxDocId = context.reader().maxDoc();
-            }
-        }
-
-        if (minDocId == maxDocId) {
-            return IteratorAndCount.empty();
-        }
-
-        if ((points.getDocCount() == context.reader().maxDoc())) {
-            return IteratorAndCount.denseRange(minDocId, maxDocId);
-        } else {
-            return IteratorAndCount.sparseRange(minDocId, maxDocId, delegate);
-        }
-    }
-
-    private IteratorAndCount getDocIdSetIteratorOrNull(LeafReaderContext context) throws IOException {
-        if (lowerValue > upperValue) {
-            return IteratorAndCount.empty();
-        }
-
-        SortedNumericDocValues sortedNumericValues = DocValues.getSortedNumeric(context.reader(), field);
-        NumericDocValues numericValues = DocValues.unwrapSingleton(sortedNumericValues);
-        if (numericValues != null) {
-            IteratorAndCount itAndCount = getDocIdSetIteratorOrNullFromBkd(context, numericValues);
-            if (itAndCount != null) {
-                return itAndCount;
-            }
-            Sort indexSort = context.reader().getMetaData().getSort();
-            if (indexSort != null && indexSort.getSort().length > 0 && indexSort.getSort()[0].getField().equals(field)) {
-
-                final SortField sortField = indexSort.getSort()[0];
-                final SortField.Type sortFieldType = getSortFieldType(sortField);
-                // The index sort optimization is only supported for Type.INT and Type.LONG
-                if (sortFieldType == Type.INT || sortFieldType == Type.LONG) {
-                    return getDocIdSetIterator(sortField, sortFieldType, context, numericValues);
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Computes the document IDs that lie within the range [lowerValue, upperValue] by performing
-     * binary search on the field's doc values.
-     *
-     * <p>Because doc values only allow forward iteration, we need to reload the field comparator
-     * every time the binary search accesses an earlier element.
-     *
-     * <p>We must also account for missing values when performing the binary search. For this reason,
-     * we load the {@link FieldComparator} instead of checking the docvalues directly. The returned
-     * {@link DocIdSetIterator} makes sure to wrap the original docvalues to skip over documents with
-     * no value.
-     */
-    private IteratorAndCount getDocIdSetIterator(
-        SortField sortField,
-        SortField.Type sortFieldType,
-        LeafReaderContext context,
-        DocIdSetIterator delegate
-    ) throws IOException {
-        long lower = sortField.getReverse() ? upperValue : lowerValue;
-        long upper = sortField.getReverse() ? lowerValue : upperValue;
-        int maxDoc = context.reader().maxDoc();
-
-        // Perform a binary search to find the first document with value >= lower.
-        ValueComparator comparator = loadComparator(sortField, sortFieldType, lower, context);
-        int low = 0;
-        int high = maxDoc - 1;
-
-        while (low <= high) {
-            int mid = (low + high) >>> 1;
-            if (comparator.compare(mid) <= 0) {
-                high = mid - 1;
-                comparator = loadComparator(sortField, sortFieldType, lower, context);
-            } else {
-                low = mid + 1;
-            }
-        }
-        int firstDocIdInclusive = high + 1;
-
-        // Perform a binary search to find the first document with value > upper.
-        // Since we know that upper >= lower, we can initialize the lower bound
-        // of the binary search to the result of the previous search.
-        comparator = loadComparator(sortField, sortFieldType, upper, context);
-        low = firstDocIdInclusive;
-        high = maxDoc - 1;
-
-        while (low <= high) {
-            int mid = (low + high) >>> 1;
-            if (comparator.compare(mid) < 0) {
-                high = mid - 1;
-                comparator = loadComparator(sortField, sortFieldType, upper, context);
-            } else {
-                low = mid + 1;
-            }
-        }
-
-        int lastDocIdExclusive = high + 1;
-
-        if (firstDocIdInclusive == lastDocIdExclusive) {
-            return IteratorAndCount.empty();
-        }
-
-        Object missingValue = sortField.getMissingValue();
-        LeafReader reader = context.reader();
-        PointValues pointValues = reader.getPointValues(field);
-        final long missingLongValue = missingValue == null ? 0L : ((Number) missingValue).longValue();
-        // all documents have docValues or missing value falls outside the range
-        if ((pointValues != null && pointValues.getDocCount() == reader.maxDoc())
-            || (missingLongValue < lowerValue || missingLongValue > upperValue)) {
-            return IteratorAndCount.denseRange(firstDocIdInclusive, lastDocIdExclusive);
-        } else {
-            return IteratorAndCount.sparseRange(firstDocIdInclusive, lastDocIdExclusive, delegate);
-        }
-    }
-
-    /** Compares the given document's value with a stored reference value. */
-    private interface ValueComparator {
-        int compare(int docID) throws IOException;
-    }
-
-    private static ValueComparator loadComparator(SortField sortField, SortField.Type type, long topValue, LeafReaderContext context)
-        throws IOException {
-        @SuppressWarnings("unchecked")
-        FieldComparator<Number> fieldComparator = (FieldComparator<Number>) sortField.getComparator(1, Pruning.NONE);
-        if (type == Type.INT) {
-            fieldComparator.setTopValue((int) topValue);
-        } else {
-            // Since we support only Type.INT and Type.LONG, assuming LONG for all other cases
-            fieldComparator.setTopValue(topValue);
-        }
-
-        LeafFieldComparator leafFieldComparator = fieldComparator.getLeafComparator(context);
-        int direction = sortField.getReverse() ? -1 : 1;
-
-        return doc -> {
-            int value = leafFieldComparator.compareTop(doc);
-            return direction * value;
-        };
-    }
-
-    private static SortField.Type getSortFieldType(SortField sortField) {
-        // We expect the sortField to be SortedNumericSortField
-        if (sortField instanceof SortedNumericSortField) {
-            return ((SortedNumericSortField) sortField).getNumericType();
-        } else {
-            return sortField.getType();
-        }
-    }
-
-    /**
-     * Provides a {@code DocIdSetIterator} along with an accurate count of documents provided by the
-     * iterator (or {@code -1} if an accurate count is unknown).
-     */
-    private static class IteratorAndCount {
-        private final DocIdSetIterator it;
-        private final int count;
-
-        IteratorAndCount(DocIdSetIterator it, int count) {
-            this.it = it;
-            this.count = count;
-        }
-
-        static IteratorAndCount empty() {
-            return new IteratorAndCount(DocIdSetIterator.empty(), 0);
-        }
-
-        static IteratorAndCount all(int maxDoc) {
-            return new IteratorAndCount(DocIdSetIterator.all(maxDoc), maxDoc);
-        }
-
-        static IteratorAndCount denseRange(int minDoc, int maxDoc) {
-            return new IteratorAndCount(DocIdSetIterator.range(minDoc, maxDoc), maxDoc - minDoc);
-        }
-
-        static IteratorAndCount sparseRange(int minDoc, int maxDoc, DocIdSetIterator delegate) {
-            return new IteratorAndCount(new BoundedDocIdSetIterator(minDoc, maxDoc, delegate), -1);
-        }
-    }
-
-    /**
-     * A doc ID set iterator that wraps a delegate iterator and only returns doc IDs in the range
-     * [firstDocInclusive, lastDoc).
-     */
-    private static class BoundedDocIdSetIterator extends DocIdSetIterator {
-        private final int firstDoc;
-        private final int lastDoc;
-        private final DocIdSetIterator delegate;
-
-        private int docID = -1;
-
-        BoundedDocIdSetIterator(int firstDoc, int lastDoc, DocIdSetIterator delegate) {
-            assert delegate != null;
-            this.firstDoc = firstDoc;
-            this.lastDoc = lastDoc;
-            this.delegate = delegate;
-        }
-
-        @Override
-        public int docID() {
-            return docID;
-        }
-
-        @Override
-        public int nextDoc() throws IOException {
-            return advance(docID + 1);
-        }
-
-        @Override
-        public int advance(int target) throws IOException {
-            if (target < firstDoc) {
-                target = firstDoc;
-            }
-
-            int result = delegate.advance(target);
-            if (result < lastDoc) {
-                docID = result;
-            } else {
-                docID = NO_MORE_DOCS;
-            }
-            return docID;
-        }
-
-        @Override
-        public long cost() {
-            return Math.min(delegate.cost(), lastDoc - firstDoc);
-        }
-    }
-}

+ 3 - 3
server/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/QueryToFilterAdapter.java

@@ -16,6 +16,7 @@ import org.apache.lucene.search.BulkScorer;
 import org.apache.lucene.search.ConstantScoreQuery;
 import org.apache.lucene.search.IndexOrDocValuesQuery;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
 import org.apache.lucene.search.LeafCollector;
 import org.apache.lucene.search.MatchNoDocsQuery;
 import org.apache.lucene.search.PointRangeQuery;
@@ -26,7 +27,6 @@ import org.apache.lucene.search.ScorerSupplier;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.util.Bits;
 import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
 import org.elasticsearch.search.aggregations.Aggregator;
 import org.elasticsearch.xcontent.XContentBuilder;
 
@@ -159,8 +159,8 @@ public class QueryToFilterAdapter {
                 query = ((ConstantScoreQuery) query).getQuery();
                 continue;
             }
-            if (query instanceof XIndexSortSortedNumericDocValuesRangeQuery) {
-                query = ((XIndexSortSortedNumericDocValuesRangeQuery) query).getFallbackQuery();
+            if (query instanceof IndexSortSortedNumericDocValuesRangeQuery) {
+                query = ((IndexSortSortedNumericDocValuesRangeQuery) query).getFallbackQuery();
                 continue;
             }
             if (query instanceof IndexOrDocValuesQuery) {

+ 3 - 3
server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java

@@ -19,6 +19,7 @@ import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.SortedNumericDocValues;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.IndexOrDocValuesQuery;
+import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.store.Directory;
 import org.elasticsearch.ElasticsearchParseException;
@@ -40,7 +41,6 @@ import org.elasticsearch.index.query.DateRangeIncludingNowQuery;
 import org.elasticsearch.index.query.QueryRewriteContext;
 import org.elasticsearch.index.query.SearchExecutionContext;
 import org.elasticsearch.index.query.SearchExecutionContextHelper;
-import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
 import org.elasticsearch.script.field.DateNanosDocValuesField;
 import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
 
@@ -467,7 +467,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
 
         Query pointQuery = LongPoint.newRangeQuery("field", instant1, instant2);
         Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery("field", instant1, instant2);
-        Query expected = new XIndexSortSortedNumericDocValuesRangeQuery(
+        Query expected = new IndexSortSortedNumericDocValuesRangeQuery(
             "field",
             instant1,
             instant2,
@@ -476,7 +476,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
         assertEquals(expected, ft.rangeQuery(date1, date2, true, true, null, null, null, context));
 
         ft = new DateFieldType("field", false);
-        expected = new XIndexSortSortedNumericDocValuesRangeQuery("field", instant1, instant2, dvQuery);
+        expected = new IndexSortSortedNumericDocValuesRangeQuery("field", instant1, instant2, dvQuery);
         assertEquals(expected, ft.rangeQuery(date1, date2, true, true, null, null, null, context));
     }
 

+ 3 - 3
server/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java

@@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.sandbox.document.HalfFloatPoint;
 import org.apache.lucene.search.IndexOrDocValuesQuery;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
 import org.apache.lucene.search.MatchNoDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
@@ -44,7 +45,6 @@ import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
 import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
 import org.elasticsearch.index.query.SearchExecutionContext;
 import org.elasticsearch.index.query.SearchExecutionContextHelper;
-import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
 import org.elasticsearch.script.ScriptCompiler;
 import org.elasticsearch.search.MultiValueMode;
 import org.elasticsearch.xcontent.XContentBuilder;
@@ -756,8 +756,8 @@ public class NumberFieldTypeTests extends FieldTypeTestCase {
                 context,
                 isIndexed
             );
-            assertThat(query, instanceOf(XIndexSortSortedNumericDocValuesRangeQuery.class));
-            Query fallbackQuery = ((XIndexSortSortedNumericDocValuesRangeQuery) query).getFallbackQuery();
+            assertThat(query, instanceOf(IndexSortSortedNumericDocValuesRangeQuery.class));
+            Query fallbackQuery = ((IndexSortSortedNumericDocValuesRangeQuery) query).getFallbackQuery();
 
             if (isIndexed) {
                 assertThat(fallbackQuery, instanceOf(IndexOrDocValuesQuery.class));

+ 2 - 2
server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java

@@ -16,6 +16,7 @@ import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.FuzzyQuery;
 import org.apache.lucene.search.IndexOrDocValuesQuery;
+import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.MatchNoDocsQuery;
 import org.apache.lucene.search.PhraseQuery;
@@ -28,7 +29,6 @@ import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
 import org.elasticsearch.common.unit.Fuzziness;
 import org.elasticsearch.core.Strings;
 import org.elasticsearch.index.query.MultiMatchQueryBuilder.Type;
-import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
 import org.elasticsearch.test.AbstractQueryTestCase;
 import org.hamcrest.Matchers;
 
@@ -172,7 +172,7 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
                     instanceOf(PointRangeQuery.class),
                     instanceOf(IndexOrDocValuesQuery.class),
                     instanceOf(PrefixQuery.class),
-                    instanceOf(XIndexSortSortedNumericDocValuesRangeQuery.class)
+                    instanceOf(IndexSortSortedNumericDocValuesRangeQuery.class)
                 )
             )
         );

+ 2 - 2
x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/lucene/TimeSeriesSortedSourceOperatorTests.java

@@ -9,6 +9,7 @@ package org.elasticsearch.compute.lucene;
 
 import org.apache.lucene.document.DoubleDocValuesField;
 import org.apache.lucene.document.FloatDocValuesField;
+import org.apache.lucene.document.LongField;
 import org.apache.lucene.document.LongPoint;
 import org.apache.lucene.document.NumericDocValuesField;
 import org.apache.lucene.document.SortedDocValuesField;
@@ -46,7 +47,6 @@ import org.elasticsearch.index.mapper.KeywordFieldMapper;
 import org.elasticsearch.index.mapper.NumberFieldMapper;
 import org.elasticsearch.index.mapper.RoutingPathFields;
 import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;
-import org.elasticsearch.lucene.document.NumericField;
 import org.hamcrest.Matcher;
 import org.junit.After;
 
@@ -237,7 +237,7 @@ public class TimeSeriesSortedSourceOperatorTests extends AnyOperatorTestCase {
             }
             try (var reader = writer.getReader()) {
                 var ctx = new LuceneSourceOperatorTests.MockShardContext(reader, 0);
-                Query query = randomFrom(NumericField.newRangeLongQuery("@timestamp", 0, t0), new MatchNoDocsQuery());
+                Query query = randomFrom(LongField.newRangeQuery("@timestamp", 0, t0), new MatchNoDocsQuery());
                 var timeSeriesFactory = TimeSeriesSortedSourceOperatorFactory.create(
                     Integer.MAX_VALUE,
                     randomIntBetween(1, 1024),

+ 2 - 2
x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongFieldMapper.java

@@ -13,6 +13,7 @@ import org.apache.lucene.document.LongPoint;
 import org.apache.lucene.document.SortedNumericDocValuesField;
 import org.apache.lucene.document.StoredField;
 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;
@@ -47,7 +48,6 @@ import org.elasticsearch.index.mapper.TimeSeriesParams;
 import org.elasticsearch.index.mapper.TimeSeriesParams.MetricType;
 import org.elasticsearch.index.mapper.ValueFetcher;
 import org.elasticsearch.index.query.SearchExecutionContext;
-import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
 import org.elasticsearch.search.DocValueFormat;
 import org.elasticsearch.search.aggregations.support.TimeSeriesValuesSourceType;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@@ -364,7 +364,7 @@ public class UnsignedLongFieldMapper extends FieldMapper {
                 Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
                 query = new IndexOrDocValuesQuery(query, dvQuery);
                 if (context.indexSortedOnField(name())) {
-                    query = new XIndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
+                    query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
                 }
             }
             return query;