Skip to content

Commit 8b45313

Browse files
make decisions to resolve wildcard any fields for only multi_match
1 parent 0accbe2 commit 8b45313

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public boolean shouldResolveInferenceFieldWildcards(QueryBuilder queryBuilder) {
103103
return multiMatchQuery.resolveInferenceFieldWildcards();
104104
}
105105

106+
@Override
107+
protected boolean shouldUseDefaultFields() {
108+
return true;
109+
}
110+
106111
private QueryBuilder buildMultiFieldSemanticQuery(
107112
MultiMatchQueryBuilder originalQuery,
108113
Set<String> inferenceFields,

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ protected Map<String, Float> getFieldsWithWeights(QueryBuilder queryBuilder) {
100100
*/
101101
protected abstract boolean shouldResolveInferenceFieldWildcards(QueryBuilder queryBuilder);
102102

103+
/**
104+
* Determines if this query type should use default fields when no fields are specified.
105+
* This is typically only needed for multi_match queries.
106+
* Default implementation returns false for most query types.
107+
*
108+
* @return true if default fields should be used when no fields are specified, false otherwise.
109+
*/
110+
protected boolean shouldUseDefaultFields() {
111+
return false;
112+
}
113+
103114
/**
104115
* Builds the inference query
105116
*
@@ -166,9 +177,9 @@ private InferenceIndexInformationForField resolveIndicesForFields(
166177
Map<String, InferenceFieldMetadata> indexInferenceFields = new HashMap<>();
167178
Map<String, InferenceFieldMetadata> indexInferenceMetadata = indexMetadata.getInferenceFields();
168179

169-
// Handle default fields per index when no fields are specified
180+
// Handle default fields per index when no fields are specified (only for multi_match queries)
170181
Map<String, Float> fieldsToProcess = fieldsWithWeights;
171-
if (fieldsToProcess.isEmpty()) {
182+
if (fieldsToProcess.isEmpty() && shouldUseDefaultFields()) {
172183
Settings settings = indexMetadata.getSettings();
173184
List<String> defaultFields = settings.getAsList(DEFAULT_FIELD_SETTING.getKey(), DEFAULT_FIELD_SETTING.getDefault(settings));
174185
fieldsToProcess = QueryParserHelper.parseFieldsAndWeights(defaultFields);

0 commit comments

Comments
 (0)