Skip to content

Commit

Permalink
Raise an exception on an array of values being sent as the factor for…
Browse files Browse the repository at this point in the history
… a field_value_factor query

closes #7408
  • Loading branch information
reuben-sutton authored and dakrone committed Feb 4, 2015
1 parent 4732ef3 commit 2436552
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -70,6 +70,8 @@ public ScoreFunction parse(QueryParseContext parseContext, XContentParser parser
} 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");
}
}

Expand Down
Expand Up @@ -100,5 +100,34 @@ public void testFieldValueFactor() throws IOException {
// 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
}

}
}

0 comments on commit 2436552

Please sign in to comment.