Skip to content

Commit

Permalink
HSEARCH-5245 Always add index.knn for OpenSearch indexes with vector …
Browse files Browse the repository at this point in the history
…fields
  • Loading branch information
marko-bekhta committed Sep 19, 2024
1 parent 82918e2 commit 67cafea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public ElasticsearchIndexValueFieldType<F> toIndexFieldType() {
builder.codec( codec );
if ( resolvedSearchable ) {
builder.searchable( true );
mappingContributor.contribute( builder, this );
builder.queryElementFactory( PredicateTypeKeys.EXISTS, new ElasticsearchExistsPredicate.Factory<>() );
}

Expand All @@ -117,6 +116,9 @@ public ElasticsearchIndexValueFieldType<F> toIndexFieldType() {

builder.multivaluable( false );

// NOTE: we make additional contribution at the end of the configuration to make sure that
// the context we pass (this) is fully configured:
mappingContributor.contribute( builder, this );
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ public final <F> void contribute(ElasticsearchIndexValueFieldType.Builder<F> bui
SearchQueryElementFactory<? extends KnnPredicateBuilder,
ElasticsearchSearchIndexScope<?>,
ElasticsearchSearchIndexValueFieldContext<F>> factory = getKnnPredicateFactory( builder );
builder.queryElementFactory( PredicateTypeKeys.KNN, factory );

builder.contributeAdditionalIndexSettings( settings -> settings.addKnn( true ) );

// only add a predicate if the field on which this contribution happens is searchable:
if ( context.searchable() ) {
builder.queryElementFactory( PredicateTypeKeys.KNN, factory );
}
}

protected abstract <F> SearchQueryElementFactory<? extends KnnPredicateBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ protected boolean indexOptionAddCondition(Context context) {

@Override
public <F> void contribute(ElasticsearchIndexValueFieldType.Builder<F> builder, Context context) {
builder.queryElementFactory( PredicateTypeKeys.KNN,
new ElasticsearchKnnPredicate.Elasticsearch812Factory<>( builder.codec() ) );
if ( context.searchable() ) {
builder.queryElementFactory( PredicateTypeKeys.KNN,
new ElasticsearchKnnPredicate.Elasticsearch812Factory<>( builder.codec() ) );
}
}

private static String resolveDefault(VectorSimilarity vectorSimilarity) {
Expand Down

0 comments on commit 67cafea

Please sign in to comment.