Skip to content

Commit

Permalink
Fix the put mapping issue for already created index with flat mapper
Browse files Browse the repository at this point in the history
Signed-off-by: Navneet Verma <navneev@amazon.com>
  • Loading branch information
navneet1v committed Feb 19, 2025
1 parent 0df5f62 commit c45820b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Features
### Enhancements
### Bug Fixes
* Fix derived source for binary and byte vectors [#2533](https://github.com/opensearch-project/k-NN/pull/2533/)
* Fix derived source for binary and byte vectors [#2533](https://github.com/opensearch-project/k-NN/pull/2533/)
* Fix the put mapping issue for already created index with flat mapper [#2542](https://github.com/opensearch-project/k-NN/pull/2542)
### Infrastructure
### Documentation
### Maintenance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public KNNVectorFieldMapper build(BuilderContext context) {
// return FlatVectorFieldMapper only for indices that are created on or after 2.17.0, for others, use either LuceneFieldMapper
// or
// MethodFieldMapper to maintain backwards compatibility
if (originalParameters.getResolvedKnnMethodContext() == null && context.indexCreatedVersion().onOrAfter(Version.V_2_17_0)) {
if (originalParameters.getResolvedKnnMethodContext() == null && indexCreatedVersion.onOrAfter(Version.V_2_17_0)) {
return FlatVectorFieldMapper.createFieldMapper(
buildFullName(context),
name,
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/opensearch/knn/index/KNNMapperSearcherIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,24 @@ public void testStoredFields_whenFloatDataType_thenSucceed() {
}
}

@SneakyThrows
public void testPutMappings_whenIndexAlreadyCreated_thenSuccess() {
List<KNNEngine> enginesToTest = List.of(KNNEngine.NMSLIB, KNNEngine.FAISS, KNNEngine.LUCENE);
float[] testVector = new float[] { -100.0f, 100.0f, 0f, 1f };
for (KNNEngine knnEngine : enginesToTest) {
String indexName = INDEX_NAME + "_" + knnEngine.getName();
createKnnIndex(indexName, createVectorMapping(testVector.length, knnEngine.getName(), VectorDataType.FLOAT.getValue(), false));
putMappingRequest(
indexName,
createVectorMapping(testVector.length, knnEngine.getName(), VectorDataType.FLOAT.getValue(), false)
);
}
// Check with FlatMapper
String indexName = INDEX_NAME + "_flat_index";
createBasicKnnIndex(indexName, FIELD_NAME, testVector.length);
putMappingRequest(indexName, createKnnIndexMapping(FIELD_NAME, testVector.length));
}

/**
* Mapping
* {
Expand Down

0 comments on commit c45820b

Please sign in to comment.