Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public static ScriptQueryBuilder fromXContent(XContentParser parser) throws IOEx
} else {
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
}
} else {
if (token != XContentParser.Token.START_ARRAY) {
throw new AssertionError("Impossible token received: " + token.name());
}
throw new ParsingException(parser.getTokenLocation(),
"[script] query does not support an array of scripts. Use a bool query with a clause per script instead.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.index.query;

import org.apache.lucene.search.Query;
import org.elasticsearch.index.query.ScriptQueryBuilder.ScriptQuery;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.script.MockScriptEngine;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
Expand All @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Set;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;

public class ScriptQueryBuilderTests extends AbstractQueryTestCase<ScriptQueryBuilder> {
Expand Down Expand Up @@ -89,6 +90,25 @@ public void testFromJson() throws IOException {
assertEquals(json, "5", parsed.script().getIdOrCode());
}

public void testArrayOfScriptsException() {
String json =
"{\n" +
" \"script\" : {\n" +
" \"script\" : [ {\n" +
" \"source\" : \"5\",\n" +
" \"lang\" : \"mockscript\"\n" +
" },\n" +
" {\n" +
" \"source\" : \"6\",\n" +
" \"lang\" : \"mockscript\"\n" +
" }\n ]" +
" }\n" +
"}";

ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertThat(e.getMessage(), containsString("does not support an array of scripts"));
}

@Override
protected Set<String> getObjectsHoldingArbitraryContent() {
//script_score.script.params can contain arbitrary parameters. no error is expected when
Expand Down