Skip to content

Commit 9338cd5

Browse files
Fixing for match query
1 parent ccd64ae commit 9338cd5

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticMatchQueryRewriteInterceptor.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ protected String getQuery(QueryBuilder queryBuilder) {
3636

3737
@Override
3838
protected QueryBuilder buildInferenceQuery(QueryBuilder queryBuilder, InferenceIndexInformationForField indexInformation) {
39-
return new SemanticQueryBuilder(indexInformation.fieldName(), getQuery(queryBuilder), false);
39+
SemanticQueryBuilder semanticQueryBuilder = new SemanticQueryBuilder(
40+
indexInformation.fieldName(),
41+
getQuery(queryBuilder),
42+
false
43+
);
44+
semanticQueryBuilder.boost(queryBuilder.boost());
45+
semanticQueryBuilder.queryName(queryBuilder.queryName());
46+
return semanticQueryBuilder;
4047
}
4148

4249
@Override
@@ -47,13 +54,14 @@ protected QueryBuilder buildCombinedInferenceAndNonInferenceQuery(
4754
assert (queryBuilder instanceof MatchQueryBuilder);
4855
MatchQueryBuilder matchQueryBuilder = (MatchQueryBuilder) queryBuilder;
4956
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
50-
boolQueryBuilder.should(
51-
createSemanticSubQuery(
52-
indexInformation.getInferenceIndices(),
53-
matchQueryBuilder.fieldName(),
54-
(String) matchQueryBuilder.value()
55-
)
57+
SemanticQueryBuilder semanticQueryBuilder = createSemanticSubQuery(
58+
indexInformation.getInferenceIndices(),
59+
matchQueryBuilder.fieldName(),
60+
(String) matchQueryBuilder.value()
5661
);
62+
semanticQueryBuilder.boost(matchQueryBuilder.boost());
63+
semanticQueryBuilder.queryName(matchQueryBuilder.queryName());
64+
boolQueryBuilder.should(semanticQueryBuilder);
5765
boolQueryBuilder.should(createSubQueryForIndices(indexInformation.nonInferenceIndices(), matchQueryBuilder));
5866
return boolQueryBuilder;
5967
}

0 commit comments

Comments
 (0)