Merge pull request #12756 from keety/terms_query_disable_coord
Add support for `disable_coord` param to `terms` query
This commit is contained in:
commit
99f4f09b84
|
@ -84,6 +84,8 @@ public class TermsQueryParser implements QueryParser {
|
||||||
String lookupRouting = null;
|
String lookupRouting = null;
|
||||||
String minShouldMatch = null;
|
String minShouldMatch = null;
|
||||||
|
|
||||||
|
boolean disableCoord = false;
|
||||||
|
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
List<Object> terms = Lists.newArrayList();
|
List<Object> terms = Lists.newArrayList();
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
|
@ -147,6 +149,8 @@ public class TermsQueryParser implements QueryParser {
|
||||||
minShouldMatch = parser.textOrNull();
|
minShouldMatch = parser.textOrNull();
|
||||||
} else if ("boost".equals(currentFieldName)) {
|
} else if ("boost".equals(currentFieldName)) {
|
||||||
boost = parser.floatValue();
|
boost = parser.floatValue();
|
||||||
|
} else if (("disable_coord").equals(currentFieldName) || ("disableCoord").equals(currentFieldName)) {
|
||||||
|
disableCoord = parser.booleanValue();
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
} else {
|
} else {
|
||||||
|
@ -191,7 +195,7 @@ public class TermsQueryParser implements QueryParser {
|
||||||
query = new TermsQuery(fieldName, filterValues);
|
query = new TermsQuery(fieldName, filterValues);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BooleanQuery bq = new BooleanQuery();
|
BooleanQuery bq = new BooleanQuery(disableCoord);
|
||||||
for (Object term : terms) {
|
for (Object term : terms) {
|
||||||
if (fieldType != null) {
|
if (fieldType != null) {
|
||||||
bq.add(fieldType.termQuery(term, parseContext), Occur.SHOULD);
|
bq.add(fieldType.termQuery(term, parseContext), Occur.SHOULD);
|
||||||
|
|
|
@ -1074,6 +1074,33 @@ public class SimpleIndexQueryParserTests extends ESSingleNodeTestCase {
|
||||||
|
|
||||||
assertThat(((TermQuery) clauses[1].getQuery()).getTerm(), equalTo(new Term("name.first", "test")));
|
assertThat(((TermQuery) clauses[1].getQuery()).getTerm(), equalTo(new Term("name.first", "test")));
|
||||||
assertThat(clauses[1].getOccur(), equalTo(BooleanClause.Occur.SHOULD));
|
assertThat(clauses[1].getOccur(), equalTo(BooleanClause.Occur.SHOULD));
|
||||||
|
|
||||||
|
assertFalse("terms query disable_coord disabled by default", booleanQuery.isCoordDisabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTermsQueryOptions() throws IOException {
|
||||||
|
IndexQueryParserService queryParser = queryParser();
|
||||||
|
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/terms-query-options.json");
|
||||||
|
Query parsedQuery = queryParser.parse(query).query();
|
||||||
|
assertThat(parsedQuery, instanceOf(BooleanQuery.class));
|
||||||
|
BooleanQuery booleanQuery = (BooleanQuery) parsedQuery;
|
||||||
|
BooleanClause[] clauses = booleanQuery.getClauses();
|
||||||
|
|
||||||
|
assertThat(clauses.length, equalTo(3));
|
||||||
|
|
||||||
|
assertThat(((TermQuery) clauses[0].getQuery()).getTerm(), equalTo(new Term("name.first", "shay")));
|
||||||
|
assertThat(clauses[0].getOccur(), equalTo(BooleanClause.Occur.SHOULD));
|
||||||
|
|
||||||
|
assertThat(((TermQuery) clauses[1].getQuery()).getTerm(), equalTo(new Term("name.first", "test")));
|
||||||
|
assertThat(clauses[1].getOccur(), equalTo(BooleanClause.Occur.SHOULD));
|
||||||
|
|
||||||
|
assertThat(((TermQuery) clauses[2].getQuery()).getTerm(), equalTo(new Term("name.first", "elasticsearch")));
|
||||||
|
assertThat(clauses[2].getOccur(), equalTo(BooleanClause.Occur.SHOULD));
|
||||||
|
|
||||||
|
assertTrue("terms query disable_coord option mismatch", booleanQuery.isCoordDisabled());
|
||||||
|
assertThat(booleanQuery.getBoost(), equalTo(2.0f));
|
||||||
|
assertThat(booleanQuery.getMinimumNumberShouldMatch(), equalTo(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"terms":{
|
||||||
|
"name.first":["shay", "test", "elasticsearch"],
|
||||||
|
"disable_coord":true,
|
||||||
|
"boost":2.0,
|
||||||
|
"min_should_match":2
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue