diff --git a/CHANGELOG.md b/CHANGELOG.md index 4258ee02c0b5d..6418fd9d5a35e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix pull-based ingestion out-of-bounds offset scenarios and remove persisted offsets ([#19607](https://github.com/opensearch-project/OpenSearch/pull/19607)) - [Star Tree] Fix sub-aggregator casting for search with profile=true ([19652](https://github.com/opensearch-project/OpenSearch/pull/19652)) - Fix issue with updating core with a patch number other than 0 ([#19377](https://github.com/opensearch-project/OpenSearch/pull/19377)) +- Fix bwc @timestamp upgrade issue by adding a version check on skip_list param ([19670](https://github.com/opensearch-project/OpenSearch/pull/19670)) ### Dependencies - Update to Gradle 9.1 ([#19575](https://github.com/opensearch-project/OpenSearch/pull/19575)) diff --git a/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java index d7b199fb1702c..25f22838b7bb8 100644 --- a/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java @@ -852,14 +852,15 @@ protected void parseCreateField(ParseContext context) throws IOException { } boolean isSkiplistDefaultEnabled(IndexSortConfig indexSortConfig, String fieldName) { - if (!isSkiplistConfigured) { - if (indexSortConfig.hasPrimarySortOnField(fieldName)) { - return true; - } - if (DataStreamFieldMapper.Defaults.TIMESTAMP_FIELD.getName().equals(fieldName)) { - return true; + if (this.indexCreatedVersion.onOrAfter(Version.V_3_3_0)) { + if (!isSkiplistConfigured) { + if (indexSortConfig.hasPrimarySortOnField(fieldName)) { + return true; + } + if (DataStreamFieldMapper.Defaults.TIMESTAMP_FIELD.getName().equals(fieldName)) { + return true; + } } - } return false; } diff --git a/server/src/test/java/org/opensearch/index/mapper/DateFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/DateFieldMapperTests.java index 551fbd89e4e87..bf3d2975244c4 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DateFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DateFieldMapperTests.java @@ -869,16 +869,25 @@ public void testSkipListIntegrationMappingDefinitionSerialization() throws IOExc public void testIsSkiplistDefaultEnabled() throws IOException { DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "date"))); + testIsSkiplistEnabled(mapper, true); + + } + + public void testIsSkiplistDefaultDisabledInOlderVersions() throws IOException { + DocumentMapper mapper = createDocumentMapper(Version.V_3_2_0, fieldMapping(b -> b.field("type", "date"))); + testIsSkiplistEnabled(mapper, false); + } + + private void testIsSkiplistEnabled(DocumentMapper mapper, boolean expectedValue) throws IOException { DateFieldMapper dateFieldMapper = (DateFieldMapper) mapper.mappers().getMapper("field"); // Test with no index sort and non-timestamp field IndexMetadata noSortindexMetadata = new IndexMetadata.Builder("index").settings(getIndexSettings()).build(); - IndexSettings noSolrIndexSettings = new IndexSettings(noSortindexMetadata, getIndexSettings()); IndexSortConfig noSortConfig = new IndexSortConfig(new IndexSettings(noSortindexMetadata, getIndexSettings())); assertFalse(dateFieldMapper.isSkiplistDefaultEnabled(noSortConfig, "field")); // timestamp field - assertTrue(dateFieldMapper.isSkiplistDefaultEnabled(noSortConfig, "@timestamp")); + assertEquals(expectedValue, dateFieldMapper.isSkiplistDefaultEnabled(noSortConfig, "@timestamp")); // Create index settings with an index sort. Settings settings = Settings.builder() @@ -892,10 +901,12 @@ public void testIsSkiplistDefaultEnabled() throws IOException { IndexMetadata indexMetadata = new IndexMetadata.Builder("index").settings(settings).build(); IndexSettings indexSettings = new IndexSettings(indexMetadata, settings); IndexSortConfig sortConfig = new IndexSortConfig(indexSettings); - assertTrue(dateFieldMapper.isSkiplistDefaultEnabled(sortConfig, "field")); - assertTrue(dateFieldMapper.isSkiplistDefaultEnabled(sortConfig, "@timestamp")); + assertEquals(expectedValue, dateFieldMapper.isSkiplistDefaultEnabled(sortConfig, "field")); + assertEquals(expectedValue, dateFieldMapper.isSkiplistDefaultEnabled(sortConfig, "@timestamp")); } + + public void testSkipListIntegrationFieldBehaviorConsistency() throws IOException { // Test that field behavior is consistent between skip_list enabled and disabled