Skip to content

Commit b4380ca

Browse files
Prevent field_caps from failing when can-match fails
`FieldCapabilitiesFetcher` performs a can-match in order to quickly return an empty response if no shard can match. However, if can-match fails for some reason, it can cause the field capabilities request to fail. An example of that is when a semantic query is used as filter. can-match will fail as it won't be able to expand the inference results of the query. In cases like that, it makes no sense to fail the field capabilities request. Instead, we should treat can-match as returning `true` to proceed. This change does that by following suit with other callers of can-match. Fixes #116106
1 parent 55536c1 commit b4380ca

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesFetcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,17 @@ private static boolean canMatchShard(
249249
QueryBuilder indexFilter,
250250
long nowInMillis,
251251
SearchExecutionContext searchExecutionContext
252-
) throws IOException {
252+
) {
253253
assert alwaysMatches(indexFilter) == false : "should not be called for always matching [" + indexFilter + "]";
254254
assert nowInMillis != 0L;
255255
ShardSearchRequest searchRequest = new ShardSearchRequest(shardId, nowInMillis, AliasFilter.EMPTY);
256256
searchRequest.source(new SearchSourceBuilder().query(indexFilter));
257-
return SearchService.queryStillMatchesAfterRewrite(searchRequest, searchExecutionContext);
257+
try {
258+
return SearchService.queryStillMatchesAfterRewrite(searchRequest, searchExecutionContext);
259+
} catch (Exception e) {
260+
// treat as if shard is still a potential match
261+
return true;
262+
}
258263
}
259264

260265
private static boolean alwaysMatches(QueryBuilder indexFilter) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public Set<NodeFeature> getTestFeatures() {
5959
SemanticTextFieldMapper.SEMANTIC_TEXT_DELETE_FIX,
6060
SemanticTextFieldMapper.SEMANTIC_TEXT_ZERO_SIZE_FIX,
6161
SemanticTextFieldMapper.SEMANTIC_TEXT_ALWAYS_EMIT_INFERENCE_ID_FIX,
62+
SemanticTextFieldMapper.SEMANTIC_TEXT_FILTER_FIELD_CAPS_FIX,
6263
SemanticTextFieldMapper.SEMANTIC_TEXT_SKIP_INFERENCE_FIELDS,
6364
SEMANTIC_TEXT_HIGHLIGHTER,
6465
SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED,

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie
136136
public static final NodeFeature SEMANTIC_TEXT_ALWAYS_EMIT_INFERENCE_ID_FIX = new NodeFeature(
137137
"semantic_text.always_emit_inference_id_fix"
138138
);
139+
public static final NodeFeature SEMANTIC_TEXT_FILTER_FIELD_CAPS_FIX = new NodeFeature("semantic_text.filter_field_caps_fix");
139140
public static final NodeFeature SEMANTIC_TEXT_HANDLE_EMPTY_INPUT = new NodeFeature("semantic_text.handle_empty_input");
140141
public static final NodeFeature SEMANTIC_TEXT_SKIP_INFERENCE_FIELDS = new NodeFeature("semantic_text.skip_inference_fields");
141142
public static final NodeFeature SEMANTIC_TEXT_BIT_VECTOR_SUPPORT = new NodeFeature("semantic_text.bit_vector_support");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
setup:
2+
- requires:
3+
cluster_features: "semantic_text.filter_field_caps_fix"
4+
reason: "fixed bug with semantic query filtering in field_caps (#116106)"
5+
6+
- do:
7+
inference.put:
8+
task_type: sparse_embedding
9+
inference_id: sparse-inference-id
10+
body: >
11+
{
12+
"service": "test_service",
13+
"service_settings": {
14+
"model": "my_model",
15+
"api_key": "abc64"
16+
},
17+
"task_settings": {
18+
}
19+
}
20+
21+
- do:
22+
indices.create:
23+
index: test-index
24+
body:
25+
mappings:
26+
properties:
27+
semantic_text_field:
28+
type: semantic_text
29+
inference_id: sparse-inference-id
30+
std_text_field:
31+
type: text
32+
33+
- do:
34+
index:
35+
index: test-index
36+
id: doc_1
37+
body:
38+
semantic_text_field: "This is a story about a cat and a dog."
39+
std_text_field: "some text"
40+
refresh: true
41+
42+
---
43+
"Field caps with semantic_text filter does not fail":
44+
- do:
45+
field_caps:
46+
index: test-index
47+
fields: "*"
48+
body:
49+
index_filter:
50+
semantic:
51+
field: "semantic_text_field"
52+
query: "test"
53+
54+
- match: { indices: [ "test-index" ] }
55+
- match: { fields.semantic_text_field.text.searchable: true }
56+
- match: { fields.std_text_field.text.searchable: true }

0 commit comments

Comments
 (0)