Skip to content

Commit c3103c7

Browse files
committed
Refactor query options
1 parent aafa278 commit c3103c7

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/AbstractMatchFullTextFunction.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1515
import org.elasticsearch.xpack.esql.common.Failure;
1616
import org.elasticsearch.xpack.esql.common.Failures;
17+
import org.elasticsearch.xpack.esql.core.InvalidArgumentException;
1718
import org.elasticsearch.xpack.esql.core.expression.Expression;
1819
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
1920
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
@@ -30,9 +31,9 @@
3031
import java.io.IOException;
3132
import java.util.List;
3233
import java.util.Map;
33-
import java.util.Objects;
3434
import java.util.Set;
3535

36+
import static org.elasticsearch.index.query.MatchQueryBuilder.LENIENT_FIELD;
3637
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
3738
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
3839
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;
@@ -216,9 +217,16 @@ protected Query translate(TranslatorHandler handler) {
216217
fieldName = multiTypeEsField.getName();
217218
}
218219
// Make query lenient so mixed field types can be queried when a field type is incompatible with the value provided
219-
return new MatchQuery(source(), fieldName, queryAsObject(), Map.of("lenient", "true"));
220+
return new MatchQuery(source(), fieldName, queryAsObject(), matchQueryOptions());
220221
}
221222

222223
throw new IllegalArgumentException("Match must have a field attribute as the first argument");
223224
}
225+
226+
/**
227+
* Returns the query options for the match query
228+
*/
229+
protected Map<String, Object> matchQueryOptions() throws InvalidArgumentException {
230+
return Map.of(LENIENT_FIELD.getPreferredName(), true);
231+
}
224232
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,25 @@ private TypeResolution resolveOptions() {
238238
}
239239

240240
try {
241-
parseOptions();
241+
matchQueryOptions();
242242
} catch (InvalidArgumentException e) {
243243
return new TypeResolution(e.getMessage());
244244
}
245245
}
246246
return TypeResolution.TYPE_RESOLVED;
247247
}
248248

249+
@Override
250+
protected Map<String, Object> matchQueryOptions() throws InvalidArgumentException {
251+
252+
if (options() == null) {
253+
return super.matchQueryOptions();
254+
}
249255

250-
private Map<String, Object> parseOptions() throws InvalidArgumentException {
251256
Map<String, Object> matchOptions = new HashMap<>();
252257
// Match is lenient by default to avoid failing on incompatible types
253258
matchOptions.put(LENIENT_FIELD.getPreferredName(), true);
254259

255-
if (options() == null) {
256-
return matchOptions;
257-
}
258-
259260
for (EntryExpression entry : ((MapExpression) options()).entryExpressions()) {
260261
Expression optionExpr = entry.key();
261262
Expression valueExpr = entry.value();

0 commit comments

Comments
 (0)