Skip to content

Fix similarity field mapping. #2666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ public void writeTypeAndParametersTo(ObjectNode objectNode) throws IOException {

if (!Similarity.Default.equals(similarity)) {
objectNode.put(FIELD_PARAM_SIMILARITY, similarity);
// similarity must have index explicitly set, otherwise Elasticsearch returns an error
objectNode.put(FIELD_PARAM_INDEX, index);
}

if (termVector != TermVector.none) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ void shouldWriteMappingWithFieldNameWithDots() {
indexOps.createWithMapping();
}

@Test // #2659
@DisplayName("should write correct mapping for dense vector property")
void shouldWriteCorrectMappingForDenseVectorProperty() {
operations.indexOps(SimilarityEntity.class).createWithMapping();
}

// region Entities
@Document(indexName = "#{@indexNameProvider.indexName()}")
static class Book {
Expand Down Expand Up @@ -893,5 +899,14 @@ private static class FieldNameDotsEntity {
@Nullable
@Field(name = "dotted.field", type = Text) private String dottedField;
}

@Document(indexName = "#{@indexNameProvider.indexName()}")
static class SimilarityEntity {
@Nullable
@Id private String id;

@Field(type = FieldType.Dense_Vector, dims = 42, similarity = "cosine") private double[] denseVector;
}

// endregion
}