Skip to content

Fix copy_to functionality with vector fields.#3162

Open
krocky-cooky wants to merge 2 commits intoopensearch-project:mainfrom
krocky-cooky:fix/vector-copyto-2636
Open

Fix copy_to functionality with vector fields.#3162
krocky-cooky wants to merge 2 commits intoopensearch-project:mainfrom
krocky-cooky:fix/vector-copyto-2636

Conversation

@krocky-cooky
Copy link

@krocky-cooky krocky-cooky commented Mar 13, 2026

Description

Previously, adding the copy_to attribute to a vector field would cause an error during indexing. The root cause of this issue is the same as the cause of geo_point issue(opensearch-project/OpenSearch#20540) and has been resolved by opensearch-project/OpenSearch#20542. This PR includes integration tests that verify the copy_to attribute works correctly on vector fields.

Related Issues

Resolves #2636

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Takuo Kuroki <kurotaku9679.sub@gmail.com>
@krocky-cooky krocky-cooky force-pushed the fix/vector-copyto-2636 branch from dbdf7f6 to 6579880 Compare March 17, 2026 15:24
Copy link
Member

@kotwanikunal kotwanikunal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krocky-cooky - Thanks for raising the PR for testing the copy_to functionality. Before we can close out the linked issue - we need some additional tests with DerivedSource enabled as well as non happy path test cases.

String targetField1 = "target_vector_1";
String targetField2 = "target_vector_2";

String mapping = XContentFactory.jsonBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of duplication with the mapping creation logic. Can you please pull it out into a helper method or extend an existing one?

.endObject()
.startObject(targetField1)
.field("type", "knn_vector")
.field("dimension", 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add in a case where the dimensions across the mappings mismatch?

assertEquals(1, results2.size());
assertEquals("1", results2.get(0).getDocId());

deleteKNNIndex(indexName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap the delete behind a finally block - that should avoid any flakiness.

}

@SneakyThrows
public void testCopyTo_whenSearchOnTargetField_thenSuccess() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please add in a new test within DerivedSourceIT with the copy to functionality? That path is crucial and we should validate copyTo works with derived source enabled before closing out the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CopyTo does not work with knn_vector fields

2 participants