diff --git a/server/src/main/java/org/opensearch/index/IndexSettings.java b/server/src/main/java/org/opensearch/index/IndexSettings.java index 9b5337948e278..1e4224c314f05 100644 --- a/server/src/main/java/org/opensearch/index/IndexSettings.java +++ b/server/src/main/java/org/opensearch/index/IndexSettings.java @@ -860,9 +860,9 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti setMergeOnFlushPolicy(scopedSettings.get(INDEX_MERGE_ON_FLUSH_POLICY)); defaultSearchPipeline = scopedSettings.get(DEFAULT_SEARCH_PIPELINE); /* There was unintentional breaking change got introduced with [OpenSearch-6424](https://github.com/opensearch-project/OpenSearch/pull/6424) (version 2.7). - * For indices created prior version (prior to 2.7) which has IndexSort type, they used to type caste the SortField.Type + * For indices created prior version (prior to 2.7) which has IndexSort type, they used to type cast the SortField.Type * to higher bytes size like integer to long. This behavior was changed from OpenSearch 2.7 version not to - * up caste the SortField to gain some sort query optimizations. + * up cast the SortField to gain some sort query optimizations. * Now this sortField (IndexSort) is stored in SegmentInfo and we need to maintain backward compatibility for them. */ widenIndexSortType = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings).before(V_2_7_0); diff --git a/server/src/main/java/org/opensearch/index/IndexSortConfig.java b/server/src/main/java/org/opensearch/index/IndexSortConfig.java index bbed50badad83..83192052564f3 100644 --- a/server/src/main/java/org/opensearch/index/IndexSortConfig.java +++ b/server/src/main/java/org/opensearch/index/IndexSortConfig.java @@ -143,7 +143,7 @@ private static MultiValueMode parseMultiValueMode(String value) { // visible for tests final FieldSortSpec[] sortSpecs; - final boolean shouldWidenIndexSortTpe; + final boolean shouldWidenIndexSortType; public IndexSortConfig(IndexSettings indexSettings) { final Settings settings = indexSettings.getSettings(); @@ -183,7 +183,7 @@ public IndexSortConfig(IndexSettings indexSettings) { sortSpecs[i].missingValue = missingValues.get(i); } } - this.shouldWidenIndexSortTpe = indexSettings.shouldWidenIndexSortType(); + this.shouldWidenIndexSortType = indexSettings.shouldWidenIndexSortType(); } /** @@ -232,7 +232,7 @@ public Sort buildIndexSort( if (fieldData == null) { throw new IllegalArgumentException("docvalues not found for index sort field:[" + sortSpec.field + "]"); } - if (this.shouldWidenIndexSortTpe == true) { + if (this.shouldWidenIndexSortType == true) { sortFields[i] = fieldData.wideSortField(sortSpec.missingValue, mode, null, reverse); } else { sortFields[i] = fieldData.sortField(sortSpec.missingValue, mode, null, reverse); diff --git a/server/src/main/java/org/opensearch/index/fielddata/IndexNumericFieldData.java b/server/src/main/java/org/opensearch/index/fielddata/IndexNumericFieldData.java index dda0b4ff72b67..b4e90b8ab570a 100644 --- a/server/src/main/java/org/opensearch/index/fielddata/IndexNumericFieldData.java +++ b/server/src/main/java/org/opensearch/index/fielddata/IndexNumericFieldData.java @@ -156,7 +156,7 @@ public final SortField wideSortField(Object missingValue, MultiValueMode sortMod // This is to support backward compatibility, the minimum number of bytes prior to OpenSearch 2.7 were 16 bytes, // i.e all sort fields were upcasted to Long/Double with 16 bytes. // Now from OpenSearch 2.7, the minimum number of bytes for sort field is 8 bytes, so if it comes as SortField INT, - // we need to up caste it to LONG to support backward compatibility info stored in segment info + // we need to up cast it to LONG to support backward compatibility info stored in segment info if (getNumericType().sortFieldType == SortField.Type.INT) { XFieldComparatorSource source = comparatorSource(NumericType.LONG, missingValue, sortMode, nested); SortedNumericSelector.Type selectorType = sortMode == MultiValueMode.MAX @@ -166,7 +166,7 @@ public final SortField wideSortField(Object missingValue, MultiValueMode sortMod sortField.setMissingValue(source.missingObject(missingValue, reverse)); return sortField; } - // If already more than INT, up caste not needed. + // If already more than INT, up cast not needed. return sortField(getNumericType(), missingValue, sortMode, nested, reverse); } @@ -243,7 +243,7 @@ private XFieldComparatorSource comparatorSource( source = new IntValuesComparatorSource(this, missingValue, sortMode, nested); } if (targetNumericType != getNumericType()) { - source.disableSkipping(); // disable skipping logic for caste of sort field + source.disableSkipping(); // disable skipping logic for cast of sort field } return source; } diff --git a/server/src/test/java/org/opensearch/index/IndexServiceTests.java b/server/src/test/java/org/opensearch/index/IndexServiceTests.java index a9fc108f6addb..db9f4bd305c79 100644 --- a/server/src/test/java/org/opensearch/index/IndexServiceTests.java +++ b/server/src/test/java/org/opensearch/index/IndexServiceTests.java @@ -543,6 +543,14 @@ public void testIndexSort() { index = createIndex("test", settings, createTestMapping("long")); assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.LONG); + // Float index sort should be remained to float sort type + index = createIndex("test", settings, createTestMapping("float")); + assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.FLOAT); + + // Double index sort should be remained to double sort type + index = createIndex("test", settings, createTestMapping("double")); + assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.DOUBLE); + // String index sort should be remained to string sort type index = createIndex("test", settings, createTestMapping("string")); assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.STRING); @@ -566,6 +574,14 @@ public void testIndexSortBackwardCompatible() { index = createIndex("test", settings, createTestMapping("long")); assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.LONG); + // Float index sort should be remained to float sort type + index = createIndex("test", settings, createTestMapping("float")); + assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.FLOAT); + + // Double index sort should be remained to double sort type + index = createIndex("test", settings, createTestMapping("double")); + assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.DOUBLE); + // String index sort should be remained to string sort type index = createIndex("test", settings, createTestMapping("string")); assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.STRING);