Fix similarity field mapping.

Original Pull Request #2666
Closes #2659
This commit is contained in:
Peter-Josef Meisch 2023-08-13 21:18:35 +02:00 committed by GitHub
parent a7185b1b84
commit 8c5ff92cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -332,6 +332,8 @@ public final class MappingParameters {
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) {

View File

@ -263,6 +263,12 @@ public abstract class MappingBuilderIntegrationTests extends MappingContextBaseT
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 {
@ -893,5 +899,14 @@ public abstract class MappingBuilderIntegrationTests extends MappingContextBaseT
@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
}