diff --git a/core/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java index 477f34d272f..1f9c842d402 100644 --- a/core/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/AndQueryBuilder.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -50,9 +51,7 @@ public class AndQueryBuilder extends AbstractQueryBuilder { * @param filters nested filters, no null values are allowed */ public AndQueryBuilder(QueryBuilder... filters) { - for (QueryBuilder filter : filters) { - this.filters.add(filter); - } + Collections.addAll(this.filters, filters); } /** @@ -65,9 +64,9 @@ public class AndQueryBuilder extends AbstractQueryBuilder { } /** - * @return the list of filters added to "and". + * @return the list of queries added to "and". */ - public List filters() { + public List innerQueries() { return this.filters; } diff --git a/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index a9cab5f656b..69ab70a0ff2 100644 --- a/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -66,14 +66,14 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder /** * @return an immutable list copy of the current sub-queries of this disjunction */ - public List queries() { + public List innerQueries() { return this.queries; } diff --git a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java index 4e1f54ec959..6808793a432 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java @@ -39,32 +39,32 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder public static final String NAME = "exists"; - private final String name; + private final String fieldName; static final ExistsQueryBuilder PROTOTYPE = new ExistsQueryBuilder(null); - public ExistsQueryBuilder(String name) { - this.name = name; + public ExistsQueryBuilder(String fieldName) { + this.fieldName = fieldName; } /** * @return the field name that has to exist for this query to match */ - public String name() { - return this.name; + public String fieldName() { + return this.fieldName; } @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); - builder.field("field", name); + builder.field("field", fieldName); printBoostAndQueryName(builder); builder.endObject(); } @Override protected Query doToQuery(QueryShardContext context) throws IOException { - return newFilter(context, name); + return newFilter(context, fieldName); } @Override @@ -119,12 +119,12 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder @Override protected int doHashCode() { - return Objects.hash(name); + return Objects.hash(fieldName); } @Override protected boolean doEquals(ExistsQueryBuilder other) { - return Objects.equals(name, other.name); + return Objects.equals(fieldName, other.fieldName); } @Override @@ -134,7 +134,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder @Override protected void doWriteTo(StreamOutput out) throws IOException { - out.writeString(name); + out.writeString(fieldName); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java index be4ee1d8fd4..471f1388954 100644 --- a/core/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/FilteredQueryBuilder.java @@ -74,12 +74,12 @@ public class FilteredQueryBuilder extends AbstractQueryBuilder { } /** - * @return the filter added to "not". + * @return the query added to "not". */ - public QueryBuilder filter() { + public QueryBuilder innerQuery() { return this.filter; } diff --git a/core/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java index 03951102eb5..1a537715859 100644 --- a/core/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/OrQueryBuilder.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -47,9 +48,7 @@ public class OrQueryBuilder extends AbstractQueryBuilder { static final OrQueryBuilder PROTOTYPE = new OrQueryBuilder(); public OrQueryBuilder(QueryBuilder... filters) { - for (QueryBuilder filter : filters) { - this.filters.add(filter); - } + Collections.addAll(this.filters, filters); } /** @@ -62,9 +61,9 @@ public class OrQueryBuilder extends AbstractQueryBuilder { } /** - * @return the list of filters added to "or". + * @return the list of queries added to "or". */ - public List filters() { + public List innerQueries() { return this.filters; } diff --git a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java index 20011557156..1387980a07b 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java @@ -94,7 +94,7 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder { this.type = type; } - public BytesRef type() { - return this.type; + public String type() { + return BytesRefs.toString(this.type); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTest.java b/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTest.java index 3944ddc6e16..30f3b014d4e 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTest.java +++ b/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTest.java @@ -53,11 +53,11 @@ public class AndQueryBuilderTest extends BaseQueryTestCase { @Override protected void doAssertLuceneQuery(AndQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - if (queryBuilder.filters().isEmpty()) { + if (queryBuilder.innerQueries().isEmpty()) { assertThat(query, nullValue()); } else { List clauses = new ArrayList<>(); - for (QueryBuilder innerFilter : queryBuilder.filters()) { + for (QueryBuilder innerFilter : queryBuilder.innerQueries()) { Query clause = innerFilter.toQuery(context); if (clause != null) { clauses.add(clause); diff --git a/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTest.java b/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTest.java index 72c157e7bd1..2b7ca52bd3d 100644 --- a/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTest.java +++ b/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTest.java @@ -39,8 +39,8 @@ public class BoostingQueryBuilderTest extends BaseQueryTestCase queries = AbstractQueryBuilder.toQueries(queryBuilder.queries(), context); + Collection queries = AbstractQueryBuilder.toQueries(queryBuilder.innerQueries(), context); if (queries.isEmpty()) { assertThat(query, nullValue()); } else { diff --git a/core/src/test/java/org/elasticsearch/index/query/ExistsQueryBuilderTest.java b/core/src/test/java/org/elasticsearch/index/query/ExistsQueryBuilderTest.java index 752d292390a..ecbd3dcad0d 100644 --- a/core/src/test/java/org/elasticsearch/index/query/ExistsQueryBuilderTest.java +++ b/core/src/test/java/org/elasticsearch/index/query/ExistsQueryBuilderTest.java @@ -55,7 +55,7 @@ public class ExistsQueryBuilderTest extends BaseQueryTestCase { @Override protected void doAssertLuceneQuery(NotQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - Query filter = queryBuilder.filter().toQuery(context); + Query filter = queryBuilder.innerQuery().toQuery(context); if (filter == null) { assertThat(query, nullValue()); } else { diff --git a/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTest.java b/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTest.java index efb9e643057..fa9ada0ace4 100644 --- a/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTest.java +++ b/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTest.java @@ -74,11 +74,11 @@ public class OrQueryBuilderTest extends BaseQueryTestCase { @Override protected void doAssertLuceneQuery(OrQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - if (queryBuilder.filters().isEmpty()) { + if (queryBuilder.innerQueries().isEmpty()) { assertThat(query, nullValue()); } else { List innerQueries = new ArrayList<>(); - for (QueryBuilder subQuery : queryBuilder.filters()) { + for (QueryBuilder subQuery : queryBuilder.innerQueries()) { Query innerQuery = subQuery.toQuery(context); // ignore queries that are null if (innerQuery != null) { diff --git a/core/src/test/java/org/elasticsearch/index/query/SimpleQueryStringBuilderTest.java b/core/src/test/java/org/elasticsearch/index/query/SimpleQueryStringBuilderTest.java index 36a24d72d7b..99da823e84e 100644 --- a/core/src/test/java/org/elasticsearch/index/query/SimpleQueryStringBuilderTest.java +++ b/core/src/test/java/org/elasticsearch/index/query/SimpleQueryStringBuilderTest.java @@ -98,7 +98,7 @@ public class SimpleQueryStringBuilderTest extends BaseQueryTestCase((MultiTermQuery)multiTermQuery).getWrappedQuery())); } diff --git a/core/src/test/java/org/elasticsearch/index/query/SpanNotQueryBuilderTest.java b/core/src/test/java/org/elasticsearch/index/query/SpanNotQueryBuilderTest.java index 33c7149c9f4..019a3c1a99e 100644 --- a/core/src/test/java/org/elasticsearch/index/query/SpanNotQueryBuilderTest.java +++ b/core/src/test/java/org/elasticsearch/index/query/SpanNotQueryBuilderTest.java @@ -58,8 +58,8 @@ public class SpanNotQueryBuilderTest extends BaseQueryTestCase { } TermQuery termQuery = (TermQuery) query; assertThat(termQuery.getTerm().field(), equalTo(TypeFieldMapper.NAME)); - assertThat(termQuery.getTerm().bytes(), equalTo(queryBuilder.type())); + assertThat(termQuery.getTerm().text(), equalTo(queryBuilder.type())); } @Test