Raise an exception on an array of values being sent as the factor for a field_value_factor query

closes #7408
This commit is contained in:
Reuben Sutton 2015-01-11 21:21:00 +00:00 committed by Lee Hinman
parent 4732ef3484
commit 2436552840
2 changed files with 31 additions and 0 deletions

View File

@ -70,6 +70,8 @@ public class FieldValueFactorFunctionParser implements ScoreFunctionParser {
} else {
throw new QueryParsingException(parseContext.index(), NAMES[0] + " query does not support [" + currentFieldName + "]");
}
} else if("factor".equals(currentFieldName) && (token == XContentParser.Token.START_ARRAY || token == XContentParser.Token.START_OBJECT)) {
throw new QueryParsingException(parseContext.index(), "[" + NAMES[0] + "] field 'factor' does not support lists or objects");
}
}

View File

@ -100,5 +100,34 @@ public class FunctionScoreFieldValueTests extends ElasticsearchIntegrationTest {
// This is fine, the query will throw an exception if executed
// locally, instead of just having failures
}
// don't permit an array of factors
try {
String querySource = "{" +
"\"query\": {" +
" \"function_score\": {" +
" \"query\": {" +
" \"match\": {\"name\": \"foo\"}" +
" }," +
" \"functions\": [" +
" {" +
" \"field_value_factor\": {" +
" \"field\": \"test\"," +
" \"factor\": [1.2,2]" +
" }" +
" }" +
" ]" +
" }" +
" }" +
"}";
response = client().prepareSearch("test")
.setSource(querySource)
.get();
assertFailures(response);
} catch (SearchPhaseExecutionException e) {
// This is fine, the query will throw an exception if executed
// locally, instead of just having failures
}
}
}