|
18 | 18 | import org.elasticsearch.common.Strings; |
19 | 19 | import org.elasticsearch.common.io.stream.StreamInput; |
20 | 20 | import org.elasticsearch.common.io.stream.StreamOutput; |
21 | | -import org.elasticsearch.index.query.BoolQueryBuilder; |
22 | | -import org.elasticsearch.index.query.BoostingQueryBuilder; |
23 | | -import org.elasticsearch.index.query.ConstantScoreQueryBuilder; |
24 | | -import org.elasticsearch.index.query.DisMaxQueryBuilder; |
25 | | -import org.elasticsearch.index.query.NestedQueryBuilder; |
26 | 21 | import org.elasticsearch.index.query.QueryBuilder; |
27 | | -import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; |
28 | 22 | import org.elasticsearch.tasks.CancellableTask; |
29 | 23 | import org.elasticsearch.tasks.Task; |
30 | 24 | import org.elasticsearch.tasks.TaskId; |
@@ -290,53 +284,9 @@ public ActionRequestValidationException validate() { |
290 | 284 | if (fields == null || fields.length == 0) { |
291 | 285 | validationException = ValidateActions.addValidationError("no fields specified", validationException); |
292 | 286 | } |
293 | | - |
294 | | - // Band-aid fix for https://github.com/elastic/elasticsearch/issues/116106. |
295 | | - // Semantic queries are high-recall queries, making them poor filters and effectively the same as an exists query when used in that |
296 | | - // context. |
297 | | - if (containsSemanticQuery(indexFilter)) { |
298 | | - validationException = ValidateActions.addValidationError( |
299 | | - "index filter cannot contain semantic queries. Use an exists query instead.", |
300 | | - validationException |
301 | | - ); |
302 | | - } |
303 | | - |
304 | 287 | return validationException; |
305 | 288 | } |
306 | 289 |
|
307 | | - /** |
308 | | - * Recursively checks if a query builder contains any semantic queries |
309 | | - */ |
310 | | - private static boolean containsSemanticQuery(QueryBuilder queryBuilder) { |
311 | | - boolean containsSemanticQuery = false; |
312 | | - |
313 | | - if (queryBuilder == null) { |
314 | | - return containsSemanticQuery; |
315 | | - } |
316 | | - |
317 | | - if ("semantic".equals(queryBuilder.getWriteableName())) { |
318 | | - containsSemanticQuery = true; |
319 | | - } else if (queryBuilder instanceof BoolQueryBuilder boolQuery) { |
320 | | - containsSemanticQuery = boolQuery.must().stream().anyMatch(FieldCapabilitiesRequest::containsSemanticQuery) |
321 | | - || boolQuery.mustNot().stream().anyMatch(FieldCapabilitiesRequest::containsSemanticQuery) |
322 | | - || boolQuery.should().stream().anyMatch(FieldCapabilitiesRequest::containsSemanticQuery) |
323 | | - || boolQuery.filter().stream().anyMatch(FieldCapabilitiesRequest::containsSemanticQuery); |
324 | | - } else if (queryBuilder instanceof DisMaxQueryBuilder disMaxQuery) { |
325 | | - containsSemanticQuery = disMaxQuery.innerQueries().stream().anyMatch(FieldCapabilitiesRequest::containsSemanticQuery); |
326 | | - } else if (queryBuilder instanceof NestedQueryBuilder nestedQuery) { |
327 | | - containsSemanticQuery = containsSemanticQuery(nestedQuery.query()); |
328 | | - } else if (queryBuilder instanceof BoostingQueryBuilder boostingQuery) { |
329 | | - containsSemanticQuery = containsSemanticQuery(boostingQuery.positiveQuery()) |
330 | | - || containsSemanticQuery(boostingQuery.negativeQuery()); |
331 | | - } else if (queryBuilder instanceof ConstantScoreQueryBuilder constantScoreQuery) { |
332 | | - containsSemanticQuery = containsSemanticQuery(constantScoreQuery.innerQuery()); |
333 | | - } else if (queryBuilder instanceof FunctionScoreQueryBuilder functionScoreQuery) { |
334 | | - containsSemanticQuery = containsSemanticQuery(functionScoreQuery.query()); |
335 | | - } |
336 | | - |
337 | | - return containsSemanticQuery; |
338 | | - } |
339 | | - |
340 | 290 | @Override |
341 | 291 | public boolean equals(Object o) { |
342 | 292 | if (this == o) return true; |
|
0 commit comments