mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-13 07:32:11 +00:00
Fix similarity field mapping.
Original Pull Request #2666 Closes #2659 (cherry picked from commit 8c5ff92cd2ec2177452dc0aa1b9307bdfcfa4e75) (cherry picked from commit 9b9136d852d61c3bcdb429ec648b1e08272e017f) # Conflicts: # src/main/java/org/springframework/data/elasticsearch/core/index/MappingParameters.java # src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderIntegrationTests.java
This commit is contained in:
parent
19ec05dae3
commit
ec8401a2fb
@ -332,6 +332,8 @@ public final class MappingParameters {
|
||||
|
||||
if (similarity != Similarity.Default) {
|
||||
objectNode.put(FIELD_PARAM_SIMILARITY, similarity.toString());
|
||||
// similarity must have index explicitly set, otherwise Elasticsearch returns an error
|
||||
objectNode.put(FIELD_PARAM_INDEX, index);
|
||||
}
|
||||
|
||||
if (termVector != TermVector.none) {
|
||||
|
@ -279,6 +279,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 {
|
||||
@ -901,5 +907,14 @@ public abstract class MappingBuilderIntegrationTests extends MappingContextBaseT
|
||||
@Nullable
|
||||
@Field(type = FieldType.Dense_Vector, dims = 1) String denseVectorField;
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user