Skip to content

Commit af1cc49

Browse files
authored
Remove support for _type in searches (#68564)
Types are no longer allowed in requests in 8.0, so we can remove support for using the `_type` field within a search request. Relates to #41059. Closes #68311.
1 parent 88bab92 commit af1cc49

File tree

18 files changed

+32
-261
lines changed

18 files changed

+32
-261
lines changed

modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ public void testUnsupportedQueries() {
653653
PercolatorFieldMapper.verifyQuery(rangeQuery1);
654654
PercolatorFieldMapper.verifyQuery(rangeQuery2);
655655

656-
HasChildQueryBuilder hasChildQuery = new HasChildQueryBuilder("_type", new MatchAllQueryBuilder(), ScoreMode.None);
656+
HasChildQueryBuilder hasChildQuery = new HasChildQueryBuilder("parent", new MatchAllQueryBuilder(), ScoreMode.None);
657657
expectThrows(IllegalArgumentException.class, () ->
658658
PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));
659659
expectThrows(IllegalArgumentException.class, () ->
@@ -671,7 +671,7 @@ public void testUnsupportedQueries() {
671671
expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasChildQuery));
672672
expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));
673673

674-
HasParentQueryBuilder hasParentQuery = new HasParentQueryBuilder("_type", new MatchAllQueryBuilder(), false);
674+
HasParentQueryBuilder hasParentQuery = new HasParentQueryBuilder("parent", new MatchAllQueryBuilder(), false);
675675
expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasParentQuery));
676676
expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasParentQuery)));
677677
}

modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ public void testIndexOrDocValuesQuery() {
951951

952952
public void testToParentBlockJoinQuery() {
953953
TermQuery termQuery = new TermQuery(new Term("field", "value"));
954-
QueryBitSetProducer queryBitSetProducer = new QueryBitSetProducer(new TermQuery(new Term("_type", "child")));
955-
ESToParentBlockJoinQuery query = new ESToParentBlockJoinQuery(termQuery, queryBitSetProducer, ScoreMode.None, "child");
954+
QueryBitSetProducer queryBitSetProducer = new QueryBitSetProducer(new TermQuery(new Term("_nested_path", "nested")));
955+
ESToParentBlockJoinQuery query = new ESToParentBlockJoinQuery(termQuery, queryBitSetProducer, ScoreMode.None, "nested");
956956
Result result = analyze(query);
957957
assertFalse(result.verified);
958958
assertThat(result.minimumShouldMatch, equalTo(1));

rest-api-spec/src/main/resources/rest-api-spec/test/search/160_exists_query.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -562,22 +562,6 @@ setup:
562562

563563
- match: {hits.total: 4}
564564

565-
---
566-
"Test exists query on _type field":
567-
568-
- do:
569-
allowed_warnings:
570-
- "[types removal] Using the _type field in queries and aggregations is deprecated, prefer to use a field instead."
571-
search:
572-
rest_total_hits_as_int: true
573-
index: test
574-
body:
575-
query:
576-
exists:
577-
field: _type
578-
579-
- match: {hits.total: 4}
580-
581565
---
582566
"Test exists query on _routing field":
583567
- do:

server/src/internalClusterTest/java/org/elasticsearch/document/DocumentActionsIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import static org.elasticsearch.client.Requests.getRequest;
3434
import static org.elasticsearch.client.Requests.indexRequest;
3535
import static org.elasticsearch.client.Requests.refreshRequest;
36-
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
36+
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
3737
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
3838
import static org.hamcrest.Matchers.equalTo;
3939
import static org.hamcrest.Matchers.nullValue;
@@ -149,7 +149,7 @@ public void testIndexActions() throws Exception {
149149
// check count
150150
for (int i = 0; i < 5; i++) {
151151
// test successful
152-
SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(termQuery("_type", "_doc"))
152+
SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(matchAllQuery())
153153
.execute().actionGet();
154154
assertNoFailures(countResponse);
155155
assertThat(countResponse.getHits().getTotalHits().value, equalTo(2L));

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ public void testWithRescore() {
12241224
.addAggregation(terms("terms")
12251225
.field(TERMS_AGGS_FIELD)
12261226
.subAggregation(
1227-
topHits("hits").sort(SortBuilders.fieldSort("_type"))
1227+
topHits("hits").sort(SortBuilders.fieldSort("_index"))
12281228
)
12291229
)
12301230
.get();
@@ -1246,7 +1246,7 @@ public void testWithRescore() {
12461246
.addAggregation(terms("terms")
12471247
.field(TERMS_AGGS_FIELD)
12481248
.subAggregation(
1249-
topHits("hits").sort(SortBuilders.scoreSort()).sort(SortBuilders.fieldSort("_type"))
1249+
topHits("hits").sort(SortBuilders.scoreSort()).sort(SortBuilders.fieldSort("_index"))
12501250
)
12511251
)
12521252
.get();

server/src/main/java/org/elasticsearch/index/mapper/FieldTypeLookup.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ final class FieldTypeLookup {
3333
* For convenience, the set of copied fields includes the field itself.
3434
*/
3535
private final Map<String, Set<String>> fieldToCopiedFields = new HashMap<>();
36-
private final String type;
3736
private final DynamicKeyFieldTypeLookup dynamicKeyLookup;
3837

3938
FieldTypeLookup(
40-
String type,
4139
Collection<FieldMapper> fieldMappers,
4240
Collection<FieldAliasMapper> fieldAliasMappers,
4341
Collection<RuntimeFieldType> runtimeFieldTypes
4442
) {
45-
this.type = type;
4643
Map<String, DynamicKeyFieldMapper> dynamicKeyMappers = new HashMap<>();
4744

4845
for (FieldMapper fieldMapper : fieldMappers) {
@@ -84,10 +81,6 @@ final class FieldTypeLookup {
8481
* Returns the mapped field type for the given field name.
8582
*/
8683
MappedFieldType get(String field) {
87-
if (field.equals(TypeFieldType.NAME)) {
88-
return new TypeFieldType(type);
89-
}
90-
9184
MappedFieldType fieldType = fullNameToFieldType.get(field);
9285
if (fieldType != null) {
9386
return fieldType;

server/src/main/java/org/elasticsearch/index/mapper/MappingLookup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public MappingLookup(Mapping mapping,
148148
}
149149
}
150150

151-
this.fieldTypeLookup = new FieldTypeLookup(mapping.root().name(), mappers, aliasMappers, mapping.root().runtimeFieldTypes());
151+
this.fieldTypeLookup = new FieldTypeLookup(mappers, aliasMappers, mapping.root().runtimeFieldTypes());
152152
this.fieldMappers = Collections.unmodifiableMap(fieldMappers);
153153
this.objectMappers = Collections.unmodifiableMap(objects);
154154
}

server/src/main/java/org/elasticsearch/index/mapper/TypeFieldType.java

Lines changed: 0 additions & 81 deletions
This file was deleted.

server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void testSegmentsWithMergeFlag() throws Exception {
353353
}
354354

355355
public void testSegmentsWithIndexSort() throws Exception {
356-
Sort indexSort = new Sort(new SortedSetSortField("_type", false));
356+
Sort indexSort = new Sort(new SortedSetSortField("field", false));
357357
try (Store store = createStore();
358358
Engine engine =
359359
createEngine(defaultSettings, store, createTempDir(),

server/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class FieldTypeLookupTests extends ESTestCase {
2525

2626
public void testEmpty() {
27-
FieldTypeLookup lookup = new FieldTypeLookup("_doc", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
27+
FieldTypeLookup lookup = new FieldTypeLookup(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
2828
assertNull(lookup.get("foo"));
2929
Collection<String> names = lookup.simpleMatchToFullName("foo");
3030
assertNotNull(names);
@@ -37,7 +37,7 @@ public void testFilter() {
3737
Collection<FieldAliasMapper> fieldAliases = singletonList(new FieldAliasMapper("alias", "alias", "test"));
3838
Collection<RuntimeFieldType> runtimeFields = List.of(
3939
new TestRuntimeField("runtime", "type"), new TestRuntimeField("field", "type"));
40-
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup("_doc", fieldMappers, fieldAliases, runtimeFields);
40+
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup(fieldMappers, fieldAliases, runtimeFields);
4141
assertEquals(3, size(fieldTypeLookup.filter(ft -> true)));
4242
for (MappedFieldType fieldType : fieldTypeLookup.filter(ft -> true)) {
4343
if (fieldType.name().equals("test")) {
@@ -66,7 +66,7 @@ public void testFilter() {
6666

6767
public void testAddNewField() {
6868
MockFieldMapper f = new MockFieldMapper("foo");
69-
FieldTypeLookup lookup = new FieldTypeLookup("_doc", Collections.singletonList(f), emptyList(), Collections.emptyList());
69+
FieldTypeLookup lookup = new FieldTypeLookup(Collections.singletonList(f), emptyList(), Collections.emptyList());
7070
assertNull(lookup.get("bar"));
7171
assertEquals(f.fieldType(), lookup.get("foo"));
7272
assertEquals(1, size(lookup.filter(ft -> true)));
@@ -76,7 +76,7 @@ public void testAddFieldAlias() {
7676
MockFieldMapper field = new MockFieldMapper("foo");
7777
FieldAliasMapper alias = new FieldAliasMapper("alias", "alias", "foo");
7878

79-
FieldTypeLookup lookup = new FieldTypeLookup("_doc", Collections.singletonList(field), Collections.singletonList(alias),
79+
FieldTypeLookup lookup = new FieldTypeLookup(Collections.singletonList(field), Collections.singletonList(alias),
8080
Collections.emptyList());
8181

8282
MappedFieldType aliasType = lookup.get("alias");
@@ -90,7 +90,7 @@ public void testSimpleMatchToFullName() {
9090
FieldAliasMapper alias1 = new FieldAliasMapper("food", "food", "foo");
9191
FieldAliasMapper alias2 = new FieldAliasMapper("barometer", "barometer", "bar");
9292

93-
FieldTypeLookup lookup = new FieldTypeLookup("_doc", List.of(field1, field2), List.of(alias1, alias2), List.of());
93+
FieldTypeLookup lookup = new FieldTypeLookup(List.of(field1, field2), List.of(alias1, alias2), List.of());
9494

9595
Collection<String> names = lookup.simpleMatchToFullName("b*");
9696

@@ -107,7 +107,7 @@ public void testSourcePathWithMultiFields() {
107107
.addMultiField(new MockFieldMapper.Builder("field.subfield2"))
108108
.build(new ContentPath());
109109

110-
FieldTypeLookup lookup = new FieldTypeLookup("_doc", singletonList(field), emptyList(), emptyList());
110+
FieldTypeLookup lookup = new FieldTypeLookup(singletonList(field), emptyList(), emptyList());
111111

112112
assertEquals(Set.of("field"), lookup.sourcePaths("field"));
113113
assertEquals(Set.of("field"), lookup.sourcePaths("field.subfield1"));
@@ -123,25 +123,17 @@ public void testSourcePathsWithCopyTo() {
123123
.copyTo("field")
124124
.build(new ContentPath());
125125

126-
FieldTypeLookup lookup = new FieldTypeLookup("_doc", Arrays.asList(field, otherField), emptyList(), emptyList());
126+
FieldTypeLookup lookup = new FieldTypeLookup(Arrays.asList(field, otherField), emptyList(), emptyList());
127127

128128
assertEquals(Set.of("other_field", "field"), lookup.sourcePaths("field"));
129129
assertEquals(Set.of("other_field", "field"), lookup.sourcePaths("field.subfield1"));
130130
}
131131

132-
public void testTypeLookup() {
133-
String type = randomAlphaOfLength(4);
134-
assertThat(
135-
((TypeFieldType) new FieldTypeLookup(type, List.of(), List.of(), List.of()).get(TypeFieldType.NAME)).getType(),
136-
equalTo(type)
137-
);
138-
}
139-
140132
public void testRuntimeFieldsLookup() {
141133
MockFieldMapper concrete = new MockFieldMapper("concrete");
142134
TestRuntimeField runtime = new TestRuntimeField("runtime", "type");
143135

144-
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup("_doc", List.of(concrete), emptyList(), List.of(runtime));
136+
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup(List.of(concrete), emptyList(), List.of(runtime));
145137
assertThat(fieldTypeLookup.get("concrete"), instanceOf(MockFieldMapper.FakeFieldType.class));
146138
assertThat(fieldTypeLookup.get("runtime"), instanceOf(TestRuntimeField.class));
147139
assertEquals(2, size(fieldTypeLookup.filter(ft -> true)));
@@ -155,7 +147,7 @@ public void testRuntimeFieldOverrides() {
155147
TestRuntimeField subfieldOverride = new TestRuntimeField("object.subfield", "type");
156148
TestRuntimeField runtime = new TestRuntimeField("runtime", "type");
157149

158-
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup("_doc", List.of(field, concrete, subfield), emptyList(),
150+
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup(List.of(field, concrete, subfield), emptyList(),
159151
List.of(fieldOverride, runtime, subfieldOverride));
160152
assertThat(fieldTypeLookup.get("field"), instanceOf(TestRuntimeField.class));
161153
assertThat(fieldTypeLookup.get("object.subfield"), instanceOf(TestRuntimeField.class));
@@ -170,7 +162,7 @@ public void testRuntimeFieldsSimpleMatchToFullName() {
170162
TestRuntimeField field2 = new TestRuntimeField("field2", "type");
171163
TestRuntimeField subfield = new TestRuntimeField("object.subfield", "type");
172164

173-
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup("_doc", List.of(field1, concrete), emptyList(), List.of(field2, subfield));
165+
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup(List.of(field1, concrete), emptyList(), List.of(field2, subfield));
174166
{
175167
Set<String> matches = fieldTypeLookup.simpleMatchToFullName("fie*");
176168
assertEquals(2, matches.size());
@@ -192,7 +184,7 @@ public void testRuntimeFieldsSourcePaths() {
192184
TestRuntimeField field2 = new TestRuntimeField("field2", "type");
193185
TestRuntimeField subfield = new TestRuntimeField("object.subfield", "type");
194186

195-
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup("_doc", List.of(field1, concrete), emptyList(), List.of(field2, subfield));
187+
FieldTypeLookup fieldTypeLookup = new FieldTypeLookup(List.of(field1, concrete), emptyList(), List.of(field2, subfield));
196188
{
197189
Set<String> sourcePaths = fieldTypeLookup.sourcePaths("field1");
198190
assertEquals(1, sourcePaths.size());

0 commit comments

Comments
 (0)