Skip to content
6 changes: 6 additions & 0 deletions docs/changelog/134879.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 134879
summary: Throw 4xx instead of 5xx for ESQL malformed query params
area: ES|QL
type: bug
issues:
- 134618
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ private static QueryParams parseParams(XContentParser p) throws IOException {
}
}
}
} else {
errors.add(
new XContentParseException(
"Unexpected token ["
+ token
+ "] at "
+ p.getTokenLocation()
+ ", expected "
+ XContentParser.Token.START_ARRAY
+ ". Please check documentation for the correct format of the 'params' field."
)
);
}
// don't allow mixed named and unnamed parameters
if (namedParams.isEmpty() == false && unNamedParams.isEmpty() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,26 @@ public void testInvalidMultivaluedUnnamedParams() throws IOException {
);
}

public void testInvalidParamsString() {
String query = randomAlphaOfLengthBetween(1, 100);
String json1 = String.format(Locale.ROOT, """
{
"query": "%s",
"params": {*}
}""", query);
Exception e1 = expectThrows(XContentParseException.class, () -> parseEsqlQueryRequestSync(json1));
String message1 = e1.getCause().getMessage();
assertThat(message1, containsString("Unexpected token [START_OBJECT]"));
String json2 = String.format(Locale.ROOT, """
{
"query": "%s",
"params": "foo"
}""", query);
Exception e2 = expectThrows(XContentParseException.class, () -> parseEsqlQueryRequestSync(json2));
String message2 = e2.getCause().getMessage();
assertThat(message2, containsString("Unexpected token [VALUE_STRING]"));
}

public void testInvalidParamsForIdentifiersPatterns() throws IOException {
String query = randomAlphaOfLengthBetween(1, 100);
boolean columnar = randomBoolean();
Expand Down