Skip to content

Commit c4726a2

Browse files
committed
Don't emit separate warnings for type filters (#63391)
#63214 made TypeFieldType a constant field, and fixed things so that it always emits deprecation warnings whenever it is referenced in a query or aggregation. However, it also emits warnings when it is used to build a type filter through the search context; this is unnecessary, as warnings are already emitted by the REST layer when types are specified as part of the URL, and it is causing failures in some BWC tests. This commit adds a specialised typeFilter method to TypeFieldType to handle this case without emitted any extra warnings. It also removes an unused duplicate TypeFieldType class that resulted from a backport merge error. Fixes #63366
1 parent e236ea4 commit c4726a2

File tree

3 files changed

+19
-87
lines changed

3 files changed

+19
-87
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import java.time.ZoneId;
4141
import java.util.Collections;
42+
import java.util.Objects;
4243
import java.util.function.Supplier;
4344

4445
public class TypeFieldMapper extends MetadataFieldMapper {
@@ -137,6 +138,22 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
137138
}
138139
return new MatchAllDocsQuery();
139140
}
141+
142+
/**
143+
* Build a type filter
144+
*
145+
* This does not emit a deprecation warning, as it is only called when a type
146+
* has been specified in a REST request and warnings will have already been
147+
* emitted at the REST layer.
148+
*/
149+
public Query typeFilter(String[] types) {
150+
for (String t : types) {
151+
if (Objects.equals(this.type, t)) {
152+
return new MatchAllDocsQuery();
153+
}
154+
}
155+
return new MatchNoDocsQuery();
156+
}
140157
}
141158

142159
private TypeFieldMapper() {

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

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

server/src/main/java/org/elasticsearch/search/DefaultSearchContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
import java.io.IOException;
7979
import java.io.UncheckedIOException;
8080
import java.util.ArrayList;
81-
import java.util.Arrays;
8281
import java.util.Collections;
8382
import java.util.HashMap;
8483
import java.util.List;
@@ -315,8 +314,8 @@ private Query createTypeFilter(String[] types) {
315314
if (mapperService().documentMapper() == null) {
316315
return null;
317316
}
318-
MappedFieldType ft = new TypeFieldMapper.TypeFieldType(mapperService().documentMapper().type());
319-
return ft.termsQuery(Arrays.asList(types), queryShardContext);
317+
TypeFieldMapper.TypeFieldType ft = new TypeFieldMapper.TypeFieldType(mapperService().documentMapper().type());
318+
return ft.typeFilter(types);
320319
}
321320
return null;
322321
}

0 commit comments

Comments
 (0)