Skip to content

Commit

Permalink
Remove type-related methods from QueryBuilders
Browse files Browse the repository at this point in the history
Removes all deprecated type-related methods from the QueryBuilders helper class
and from tests using them. Also removing related docs tests and doc pages
refering to the `type` query. All removed methods have been deprecated since
version 7.0.
  • Loading branch information
Christoph Büscher committed May 21, 2019
1 parent 49bd667 commit 4a70f82
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import static org.elasticsearch.index.query.QueryBuilders.spanWithinQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
import static org.elasticsearch.index.query.QueryBuilders.typeQuery;
import static org.elasticsearch.index.query.QueryBuilders.wildcardQuery;
import static org.elasticsearch.index.query.QueryBuilders.wrapperQuery;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.exponentialDecayFunction;
Expand Down Expand Up @@ -433,12 +432,6 @@ public void testTerms() {
// end::terms
}

public void testType() {
// tag::type
typeQuery("my_type"); // <1>
// end::type
}

public void testWildcard() {
// tag::wildcard
wildcardQuery(
Expand Down
6 changes: 0 additions & 6 deletions docs/java-api/query-dsl/term-level-queries.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ The queries in this group are:
http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance[Levenshtein edit distance]
of 1 or 2.

<<java-query-dsl-type-query,`type` query>>::

Find documents of the specified type.

<<java-query-dsl-ids-query,`ids` query>>::

Find documents with the specified type and IDs.
Expand All @@ -78,6 +74,4 @@ include::regexp-query.asciidoc[]

include::fuzzy-query.asciidoc[]

include::type-query.asciidoc[]

include::ids-query.asciidoc[]
15 changes: 0 additions & 15 deletions docs/java-api/query-dsl/type-query.asciidoc

This file was deleted.

8 changes: 1 addition & 7 deletions docs/reference/query-dsl/term-level-queries.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ The queries in this group are:
http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance[Levenshtein edit distance]
of 1 or 2.

<<query-dsl-type-query,`type` query>>::

Find documents of the specified type.

<<query-dsl-ids-query,`ids` query>>::

Find documents with the specified type and IDs.
Find documents with the specified IDs.


include::term-query.asciidoc[]
Expand All @@ -87,6 +83,4 @@ include::regexp-query.asciidoc[]

include::fuzzy-query.asciidoc[]

include::type-query.asciidoc[]

include::ids-query.asciidoc[]
19 changes: 0 additions & 19 deletions docs/reference/query-dsl/type-query.asciidoc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void testSimpleChildQuery() throws Exception {
// TEST FETCHING _parent from child
SearchResponse searchResponse;
searchResponse = client().prepareSearch("test")
.setQuery(idsQuery("doc").addIds("c1")).get();
.setQuery(idsQuery().addIds("c1")).get();
assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void testThatGeoShapeQueryGetRequestContainsContextAndHeaders() throws Ex
.get();
transportClient().admin().indices().prepareRefresh(lookupIndex, queryIndex).get();

GeoShapeQueryBuilder queryBuilder = QueryBuilders.geoShapeQuery("location", "1", "type")
GeoShapeQueryBuilder queryBuilder = QueryBuilders.geoShapeQuery("location", "1")
.indexedShapeIndex(lookupIndex)
.indexedShapePath("location");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@ public static IdsQueryBuilder idsQuery() {
return new IdsQueryBuilder();
}

/**
* Constructs a query that will match only specific ids within types.
*
* @param types The mapping/doc type
*
* @deprecated Types are in the process of being removed, use {@link #idsQuery()} instead.
*/
@Deprecated
public static IdsQueryBuilder idsQuery(String... types) {
return new IdsQueryBuilder().types(types);
}

/**
* A Query that matches documents containing a term.
*
Expand Down Expand Up @@ -426,7 +414,7 @@ public static FunctionScoreQueryBuilder functionScoreQuery(FunctionScoreQueryBui
*
* @param function The function builder used to custom score
*/
public static FunctionScoreQueryBuilder functionScoreQuery(ScoreFunctionBuilder function) {
public static FunctionScoreQueryBuilder functionScoreQuery(ScoreFunctionBuilder<?> function) {
return new FunctionScoreQueryBuilder(function);
}

Expand All @@ -436,7 +424,7 @@ public static FunctionScoreQueryBuilder functionScoreQuery(ScoreFunctionBuilder
* @param queryBuilder The query to custom score
* @param function The function builder used to custom score
*/
public static FunctionScoreQueryBuilder functionScoreQuery(QueryBuilder queryBuilder, ScoreFunctionBuilder function) {
public static FunctionScoreQueryBuilder functionScoreQuery(QueryBuilder queryBuilder, ScoreFunctionBuilder<?> function) {
return (new FunctionScoreQueryBuilder(queryBuilder, function));
}

Expand Down Expand Up @@ -586,15 +574,6 @@ public static WrapperQueryBuilder wrapperQuery(byte[] source) {
return new WrapperQueryBuilder(source);
}

/**
* A filter based on doc/mapping type.
* @deprecated Types are going away, prefer filtering on a field.
*/
@Deprecated
public static TypeQueryBuilder typeQuery(String type) {
return new TypeQueryBuilder(type);
}

/**
* A terms query that can extract the terms from another doc in an index.
*/
Expand Down Expand Up @@ -653,14 +632,6 @@ public static GeoShapeQueryBuilder geoShapeQuery(String name, String indexedShap
return new GeoShapeQueryBuilder(name, indexedShapeId);
}

/**
* @deprecated Types are in the process of being removed, use {@link #geoShapeQuery(String, String)} instead.
*/
@Deprecated
public static GeoShapeQueryBuilder geoShapeQuery(String name, String indexedShapeId, String indexedShapeType) {
return new GeoShapeQueryBuilder(name, indexedShapeId, indexedShapeType);
}

/**
* A filter to filter indexed shapes intersecting with shapes
*
Expand All @@ -679,16 +650,6 @@ public static GeoShapeQueryBuilder geoIntersectionQuery(String name, String inde
return builder;
}

/**
* @deprecated Types are in the process of being removed, use {@link #geoIntersectionQuery(String, String)} instead.
*/
@Deprecated
public static GeoShapeQueryBuilder geoIntersectionQuery(String name, String indexedShapeId, String indexedShapeType) {
GeoShapeQueryBuilder builder = geoShapeQuery(name, indexedShapeId, indexedShapeType);
builder.relation(ShapeRelation.INTERSECTS);
return builder;
}

/**
* A filter to filter indexed shapes that are contained by a shape
*
Expand All @@ -707,16 +668,6 @@ public static GeoShapeQueryBuilder geoWithinQuery(String name, String indexedSha
return builder;
}

/**
* @deprecated Types are in the process of being removed, use {@link #geoWithinQuery(String, String)} instead.
*/
@Deprecated
public static GeoShapeQueryBuilder geoWithinQuery(String name, String indexedShapeId, String indexedShapeType) {
GeoShapeQueryBuilder builder = geoShapeQuery(name, indexedShapeId, indexedShapeType);
builder.relation(ShapeRelation.WITHIN);
return builder;
}

/**
* A filter to filter indexed shapes that are not intersection with the query shape
*
Expand All @@ -735,16 +686,6 @@ public static GeoShapeQueryBuilder geoDisjointQuery(String name, String indexedS
return builder;
}

/**
* @deprecated Types are in the process of being removed, use {@link #geoDisjointQuery(String, String)} instead.
*/
@Deprecated
public static GeoShapeQueryBuilder geoDisjointQuery(String name, String indexedShapeId, String indexedShapeType) {
GeoShapeQueryBuilder builder = geoShapeQuery(name, indexedShapeId, indexedShapeType);
builder.relation(ShapeRelation.DISJOINT);
return builder;
}

/**
* A filter to filter only documents where a field exists in them.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.elasticsearch.search.fetch.subphase.highlight;

import com.carrotsearch.randomizedtesting.generators.RandomPicks;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
Expand Down Expand Up @@ -1801,7 +1802,7 @@ public void testHighlightNoMatchSizeWithMultivaluedFields() throws IOException {
index("test", "type1", "2", "text", new String[] {"", text2});
refresh();

IdsQueryBuilder idsQueryBuilder = QueryBuilders.idsQuery("type1").addIds("2");
IdsQueryBuilder idsQueryBuilder = QueryBuilders.idsQuery().addIds("2");
field.highlighterType("plain");
response = client().prepareSearch("test")
.setQuery(idsQueryBuilder)
Expand All @@ -1824,7 +1825,7 @@ public void testHighlightNoMatchSizeWithMultivaluedFields() throws IOException {
// But if the field was actually empty then you should get no highlighting field
index("test", "type1", "3", "text", new String[] {});
refresh();
idsQueryBuilder = QueryBuilders.idsQuery("type1").addIds("3");
idsQueryBuilder = QueryBuilders.idsQuery().addIds("3");
field.highlighterType("plain");
response = client().prepareSearch("test")
.setQuery(idsQueryBuilder)
Expand All @@ -1847,7 +1848,7 @@ public void testHighlightNoMatchSizeWithMultivaluedFields() throws IOException {
index("test", "type1", "4");
refresh();

idsQueryBuilder = QueryBuilders.idsQuery("type1").addIds("4");
idsQueryBuilder = QueryBuilders.idsQuery().addIds("4");
field.highlighterType("plain");
response = client().prepareSearch("test")
.setQuery(idsQueryBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testIndexShapeRouting() throws Exception {
indexRandom(true, client().prepareIndex("test", "doc", "0").setSource(source, XContentType.JSON).setRouting("ABC"));

SearchResponse searchResponse = client().prepareSearch("test").setQuery(
geoShapeQuery("shape", "0", "doc").indexedShapeIndex("test").indexedShapeRouting("ABC")
geoShapeQuery("shape", "0").indexedShapeIndex("test").indexedShapeRouting("ABC")
).get();

assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.search.geo;

import com.carrotsearch.randomizedtesting.generators.RandomNumbers;

import org.apache.lucene.geo.GeoTestUtil;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
Expand Down Expand Up @@ -233,7 +234,7 @@ public void testIndexedShapeReferenceWithTypes() throws Exception {
.endObject()).setRefreshPolicy(IMMEDIATE).get();

SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(geoIntersectionQuery("location", "Big_Rectangle", "shape_type"))
.setQuery(geoIntersectionQuery("location", "Big_Rectangle"))
.get();

assertSearchResponse(searchResponse);
Expand All @@ -242,7 +243,7 @@ public void testIndexedShapeReferenceWithTypes() throws Exception {
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1"));

searchResponse = client().prepareSearch("test")
.setQuery(geoShapeQuery("location", "Big_Rectangle", "shape_type"))
.setQuery(geoShapeQuery("location", "Big_Rectangle"))
.get();

assertSearchResponse(searchResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void testIndexShapeRouting() throws Exception {
indexRandom(true, client().prepareIndex("test", "doc", "0").setSource(source, XContentType.JSON).setRouting("ABC"));

SearchResponse searchResponse = client().prepareSearch("test").setQuery(
geoShapeQuery("shape", "0", "doc").indexedShapeIndex("test").indexedShapeRouting("ABC")
geoShapeQuery("shape", "0").indexedShapeIndex("test").indexedShapeRouting("ABC")
).get();

assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateFormatter;
Expand Down Expand Up @@ -92,7 +91,6 @@
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsLookupQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
import static org.elasticsearch.index.query.QueryBuilders.typeQuery;
import static org.elasticsearch.index.query.QueryBuilders.wildcardQuery;
import static org.elasticsearch.index.query.QueryBuilders.wrapperQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
Expand Down Expand Up @@ -486,9 +484,6 @@ public void testTypeFilter() throws Exception {
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "value1"),
client().prepareIndex("test", "type1", "2").setSource("field1", "value1"));

assertHitCount(client().prepareSearch().setQuery(typeQuery("type1")).get(), 2L);
assertHitCount(client().prepareSearch().setQuery(typeQuery("type2")).get(), 0L);

assertHitCount(client().prepareSearch().setTypes("type1").setQuery(matchAllQuery()).get(), 2L);
assertHitCount(client().prepareSearch().setTypes("type2").setQuery(matchAllQuery()).get(), 0L);

Expand All @@ -502,7 +497,7 @@ public void testIdsQueryTestsIdIndexed() throws Exception {
client().prepareIndex("test", "type1", "2").setSource("field1", "value2"),
client().prepareIndex("test", "type1", "3").setSource("field1", "value3"));

SearchResponse searchResponse = client().prepareSearch().setQuery(constantScoreQuery(idsQuery("type1").addIds("1", "3"))).get();
SearchResponse searchResponse = client().prepareSearch().setQuery(constantScoreQuery(idsQuery().addIds("1", "3"))).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");

Expand All @@ -511,7 +506,7 @@ public void testIdsQueryTestsIdIndexed() throws Exception {
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");

searchResponse = client().prepareSearch().setQuery(idsQuery("type1").addIds("1", "3")).get();
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "3")).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");

Expand All @@ -520,7 +515,7 @@ public void testIdsQueryTestsIdIndexed() throws Exception {
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");

searchResponse = client().prepareSearch().setQuery(idsQuery("type1").addIds("7", "10")).get();
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("7", "10")).get();
assertHitCount(searchResponse, 0L);

// repeat..., with terms
Expand Down Expand Up @@ -1156,7 +1151,7 @@ public void testBasicQueryById() throws Exception {
client().prepareIndex("test", "_doc", "3").setSource("field1", "value3").get();
refresh();

SearchResponse searchResponse = client().prepareSearch().setQuery(idsQuery("_doc").addIds("1", "2")).get();
SearchResponse searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "2")).get();
assertHitCount(searchResponse, 2L);
assertThat(searchResponse.getHits().getHits().length, equalTo(2));

Expand All @@ -1168,11 +1163,11 @@ public void testBasicQueryById() throws Exception {
assertHitCount(searchResponse, 2L);
assertThat(searchResponse.getHits().getHits().length, equalTo(2));

searchResponse = client().prepareSearch().setQuery(idsQuery(Strings.EMPTY_ARRAY).addIds("1")).get();
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1")).get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getHits().length, equalTo(1));

searchResponse = client().prepareSearch().setQuery(idsQuery("type1", "type2", "_doc").addIds("1", "2", "3", "4")).get();
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "2", "3", "4")).get();
assertHitCount(searchResponse, 3L);
assertThat(searchResponse.getHits().getHits().length, equalTo(3));
}
Expand Down

0 comments on commit 4a70f82

Please sign in to comment.