Skip to content

Return BAD_REQUEST when a field scorer references a missing field #127229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/127229.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 127229
summary: Return BAD_REQUEST when a field scorer references a missing field
area: Ranking
type: bug
issues:
- 127162
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ setup:
- match: { hits.hits.1._score: 20 }
- match: { hits.hits.2._score: 10 }

---
"referencing a missing field returns bad request":
- requires:
cluster_features: [ "search.rescorer.missing.field.bad.request" ]
reason: "Testing the behaviour change with this feature"
- do:
catch: bad_request
search:
index: test
body:
rescore:
example:
factor: 1
factor_field: missing
- match: { status: 400 }
- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.root_cause.0.reason: "Missing value for field [missing]" }

---
"sorted based on a numeric field and rescored based on a factor field using a window size":
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Explanation;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
Expand Down Expand Up @@ -73,7 +72,7 @@ public double score(int docId, float subQueryScore) throws IOException {
if (missing != null) {
value = missing;
} else {
throw new ElasticsearchException("Missing value for field [" + field + "]");
throw new IllegalArgumentException("Missing value for field [" + field + "]");
}
}
double val = value * boostFactor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ public Set<NodeFeature> getFeatures() {
public static final NodeFeature COMPLETION_FIELD_SUPPORTS_DUPLICATE_SUGGESTIONS = new NodeFeature(
"search.completion_field.duplicate.support"
);
public static final NodeFeature RESCORER_MISSING_FIELD_BAD_REQUEST = new NodeFeature("search.rescorer.missing.field.bad.request");

@Override
public Set<NodeFeature> getTestFeatures() {
return Set.of(RETRIEVER_RESCORER_ENABLED, COMPLETION_FIELD_SUPPORTS_DUPLICATE_SUGGESTIONS);
return Set.of(RETRIEVER_RESCORER_ENABLED, COMPLETION_FIELD_SUPPORTS_DUPLICATE_SUGGESTIONS, RESCORER_MISSING_FIELD_BAD_REQUEST);
}
}
Loading