Skip to content

Commit d4c2da0

Browse files
committed
HSEARCH-4950 Fail faster for older dialects not supporting vectors
1 parent 6a4bc39 commit d4c2da0

File tree

22 files changed

+239
-32
lines changed

22 files changed

+239
-32
lines changed

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/dialect/model/impl/Elasticsearch8ModelDialect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77
package org.hibernate.search.backend.elasticsearch.dialect.model.impl;
88

9-
import org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl.Elasticsearch7IndexFieldTypeFactoryProvider;
9+
import org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl.Elasticsearch8IndexFieldTypeFactoryProvider;
1010
import org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl.ElasticsearchIndexFieldTypeFactoryProvider;
11-
import org.hibernate.search.backend.elasticsearch.validation.impl.Elasticsearch7PropertyMappingValidatorProvider;
11+
import org.hibernate.search.backend.elasticsearch.validation.impl.Elasticsearch8PropertyMappingValidatorProvider;
1212
import org.hibernate.search.backend.elasticsearch.validation.impl.ElasticsearchPropertyMappingValidatorProvider;
1313

1414
import com.google.gson.Gson;
@@ -20,11 +20,11 @@ public class Elasticsearch8ModelDialect implements ElasticsearchModelDialect {
2020

2121
@Override
2222
public ElasticsearchIndexFieldTypeFactoryProvider createIndexTypeFieldFactoryProvider(Gson userFacingGson) {
23-
return new Elasticsearch7IndexFieldTypeFactoryProvider( userFacingGson );
23+
return new Elasticsearch8IndexFieldTypeFactoryProvider( userFacingGson );
2424
}
2525

2626
@Override
2727
public ElasticsearchPropertyMappingValidatorProvider createElasticsearchPropertyMappingValidatorProvider() {
28-
return new Elasticsearch7PropertyMappingValidatorProvider();
28+
return new Elasticsearch8PropertyMappingValidatorProvider();
2929
}
3030
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/dialect/model/impl/OpenSearch2ModelDialect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
package org.hibernate.search.backend.elasticsearch.dialect.model.impl;
88

99
import org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl.ElasticsearchIndexFieldTypeFactoryProvider;
10-
import org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl.OpenSearch1IndexFieldTypeFactoryProvider;
10+
import org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl.OpenSearch2IndexFieldTypeFactoryProvider;
1111
import org.hibernate.search.backend.elasticsearch.validation.impl.ElasticsearchPropertyMappingValidatorProvider;
12-
import org.hibernate.search.backend.elasticsearch.validation.impl.OpenSearch1PropertyMappingValidatorProvider;
12+
import org.hibernate.search.backend.elasticsearch.validation.impl.OpenSearch2PropertyMappingValidatorProvider;
1313

1414
import com.google.gson.Gson;
1515

@@ -20,11 +20,11 @@ public class OpenSearch2ModelDialect implements ElasticsearchModelDialect {
2020

2121
@Override
2222
public ElasticsearchIndexFieldTypeFactoryProvider createIndexTypeFieldFactoryProvider(Gson userFacingGson) {
23-
return new OpenSearch1IndexFieldTypeFactoryProvider( userFacingGson );
23+
return new OpenSearch2IndexFieldTypeFactoryProvider( userFacingGson );
2424
}
2525

2626
@Override
2727
public ElasticsearchPropertyMappingValidatorProvider createElasticsearchPropertyMappingValidatorProvider() {
28-
return new OpenSearch1PropertyMappingValidatorProvider();
28+
return new OpenSearch2PropertyMappingValidatorProvider();
2929
}
3030
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/Log.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,13 @@ SearchException vectorKnnMatchVectorTypeDiffersFromField(String absoluteFieldPat
876876
+ "This option is only applicable to an Elasticsearch distribution of an Elasticsearch backend.")
877877
SearchException knnNumberOfCandidatesUnsupportedOption();
878878

879-
@Message(id = ID_OFFSET + 185,
879+
@Message(id = ID_OFFSET + 186,
880880
value = "An %1$s distribution version in use is not compatible with the Hibernate Search integration of vector search. "
881881
+ "Update your %1$s cluster to a %2$s series to get vector search integration enabled.")
882882
SearchException searchBackendVersionIncompatibleWithVectorIntegration(String distribution, String version);
883883

884884
@LogMessage(level = Logger.Level.WARN)
885-
@Message(id = ID_OFFSET + 186,
885+
@Message(id = ID_OFFSET + 187,
886886
value = "Elasticsearch distribution does not allow to apply constant score to a knn predicate."
887887
+ " Constant score will not be applied.")
888888
void elasticsearchKnnIgnoresConstantScore();

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/types/dsl/provider/impl/Elasticsearch7IndexFieldTypeFactoryProvider.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
*/
77
package org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl;
88

9-
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.Elasticsearch7VectorFieldTypeMappingContributor;
9+
import java.lang.invoke.MethodHandles;
10+
11+
import org.hibernate.search.backend.elasticsearch.logging.impl.Log;
12+
import org.hibernate.search.backend.elasticsearch.lowlevel.index.mapping.impl.PropertyMapping;
13+
import org.hibernate.search.backend.elasticsearch.types.impl.ElasticsearchIndexValueFieldType;
1014
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.ElasticsearchVectorFieldTypeMappingContributor;
15+
import org.hibernate.search.util.common.logging.impl.LoggerFactory;
1116

1217
import com.google.gson.Gson;
1318

@@ -16,8 +21,21 @@
1621
*/
1722
public class Elasticsearch7IndexFieldTypeFactoryProvider extends AbstractIndexFieldTypeFactoryProvider {
1823

19-
private final Elasticsearch7VectorFieldTypeMappingContributor vectorFieldTypeMappingContributor =
20-
new Elasticsearch7VectorFieldTypeMappingContributor();
24+
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );
25+
26+
private final ElasticsearchVectorFieldTypeMappingContributor vectorFieldTypeMappingContributor =
27+
new ElasticsearchVectorFieldTypeMappingContributor() {
28+
29+
@Override
30+
public void contribute(PropertyMapping mapping, Context context) {
31+
throw log.searchBackendVersionIncompatibleWithVectorIntegration( "Elasticsearch", "8.x" );
32+
}
33+
34+
@Override
35+
public <F> void contribute(ElasticsearchIndexValueFieldType.Builder<F> builder, Context context) {
36+
throw log.searchBackendVersionIncompatibleWithVectorIntegration( "Elasticsearch", "8.x" );
37+
}
38+
};
2139

2240
public Elasticsearch7IndexFieldTypeFactoryProvider(Gson userFacingGson) {
2341
super( userFacingGson );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Hibernate Search, full-text search for your domain model
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl;
8+
9+
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.Elasticsearch8VectorFieldTypeMappingContributor;
10+
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.ElasticsearchVectorFieldTypeMappingContributor;
11+
12+
import com.google.gson.Gson;
13+
14+
/**
15+
* The index field type factory provider for ES8.x.
16+
*/
17+
public class Elasticsearch8IndexFieldTypeFactoryProvider extends AbstractIndexFieldTypeFactoryProvider {
18+
19+
private final Elasticsearch8VectorFieldTypeMappingContributor vectorFieldTypeMappingContributor =
20+
new Elasticsearch8VectorFieldTypeMappingContributor();
21+
22+
public Elasticsearch8IndexFieldTypeFactoryProvider(Gson userFacingGson) {
23+
super( userFacingGson );
24+
}
25+
26+
@Override
27+
protected ElasticsearchVectorFieldTypeMappingContributor vectorFieldTypeMappingContributor() {
28+
return vectorFieldTypeMappingContributor;
29+
}
30+
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/types/dsl/provider/impl/OpenSearch1IndexFieldTypeFactoryProvider.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,36 @@
66
*/
77
package org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl;
88

9+
import java.lang.invoke.MethodHandles;
10+
11+
import org.hibernate.search.backend.elasticsearch.logging.impl.Log;
12+
import org.hibernate.search.backend.elasticsearch.lowlevel.index.mapping.impl.PropertyMapping;
13+
import org.hibernate.search.backend.elasticsearch.types.impl.ElasticsearchIndexValueFieldType;
914
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.ElasticsearchVectorFieldTypeMappingContributor;
10-
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.OpenSearch1VectorFieldTypeMappingContributor;
15+
import org.hibernate.search.util.common.logging.impl.LoggerFactory;
1116

1217
import com.google.gson.Gson;
1318

1419
/**
15-
* The index field type factory provider for OpenSearch 1.x/2.x.
20+
* The index field type factory provider for OpenSearch 1.x.
1621
*/
1722
public class OpenSearch1IndexFieldTypeFactoryProvider extends AbstractIndexFieldTypeFactoryProvider {
1823

19-
private final OpenSearch1VectorFieldTypeMappingContributor vectorFieldTypeMappingContributor =
20-
new OpenSearch1VectorFieldTypeMappingContributor();
24+
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );
25+
26+
private final ElasticsearchVectorFieldTypeMappingContributor vectorFieldTypeMappingContributor =
27+
new ElasticsearchVectorFieldTypeMappingContributor() {
28+
29+
@Override
30+
public void contribute(PropertyMapping mapping, Context context) {
31+
throw log.searchBackendVersionIncompatibleWithVectorIntegration( "OpenSearch", "2.x" );
32+
}
33+
34+
@Override
35+
public <F> void contribute(ElasticsearchIndexValueFieldType.Builder<F> builder, Context context) {
36+
throw log.searchBackendVersionIncompatibleWithVectorIntegration( "OpenSearch", "2.x" );
37+
}
38+
};
2139

2240
public OpenSearch1IndexFieldTypeFactoryProvider(Gson userFacingGson) {
2341
super( userFacingGson );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Hibernate Search, full-text search for your domain model
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.search.backend.elasticsearch.types.dsl.provider.impl;
8+
9+
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.ElasticsearchVectorFieldTypeMappingContributor;
10+
import org.hibernate.search.backend.elasticsearch.types.mapping.impl.OpenSearch2VectorFieldTypeMappingContributor;
11+
12+
import com.google.gson.Gson;
13+
14+
/**
15+
* The index field type factory provider for OpenSearch 2.x.
16+
*/
17+
public class OpenSearch2IndexFieldTypeFactoryProvider extends AbstractIndexFieldTypeFactoryProvider {
18+
19+
private final OpenSearch2VectorFieldTypeMappingContributor vectorFieldTypeMappingContributor =
20+
new OpenSearch2VectorFieldTypeMappingContributor();
21+
22+
public OpenSearch2IndexFieldTypeFactoryProvider(Gson userFacingGson) {
23+
super( userFacingGson );
24+
}
25+
26+
@Override
27+
protected ElasticsearchVectorFieldTypeMappingContributor vectorFieldTypeMappingContributor() {
28+
return vectorFieldTypeMappingContributor;
29+
}
30+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import com.google.gson.JsonObject;
1818

19-
public class Elasticsearch7VectorFieldTypeMappingContributor implements ElasticsearchVectorFieldTypeMappingContributor {
19+
public class Elasticsearch8VectorFieldTypeMappingContributor implements ElasticsearchVectorFieldTypeMappingContributor {
2020
@Override
2121
public void contribute(PropertyMapping mapping, Context context) {
2222
mapping.setType( DataTypes.DENSE_VECTOR );
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import com.google.gson.JsonObject;
1818

19-
public class OpenSearch1VectorFieldTypeMappingContributor implements ElasticsearchVectorFieldTypeMappingContributor {
19+
public class OpenSearch2VectorFieldTypeMappingContributor implements ElasticsearchVectorFieldTypeMappingContributor {
2020

2121
private static final String BYTE_TYPE = "BYTE";
2222

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/validation/impl/Elasticsearch7PropertyMappingValidatorProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
public class Elasticsearch7PropertyMappingValidatorProvider implements ElasticsearchPropertyMappingValidatorProvider {
1212
@Override
1313
public Validator<PropertyMapping> create() {
14-
return new PropertyMappingValidator.ElasticsearchPropertyMappingValidator();
14+
return new PropertyMappingValidator.Elasticsearch7PropertyMappingValidator();
1515
}
1616
}

0 commit comments

Comments
 (0)