Skip to content

Commit 0bac64f

Browse files
authored
Deprecate the _type field in aggregations. (#37131)
1 parent e40193a commit 0bac64f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

server/src/main/java/org/elasticsearch/index/query/QueryShardContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
public class QueryShardContext extends QueryRewriteContext {
7676
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
7777
LogManager.getLogger(QueryShardContext.class));
78-
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using the _type field " +
79-
"in queries is deprecated, prefer to filter on a field instead.";
78+
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using the _type field " +
79+
"in queries and aggregations is deprecated, prefer to use a field instead.";
8080

8181
private final ScriptService scriptService;
8282
private final IndexSettings indexSettings;

server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.index.IndexService;
2828
import org.elasticsearch.index.engine.Engine.Searcher;
2929
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
30+
import org.elasticsearch.index.mapper.TypeFieldMapper;
3031
import org.elasticsearch.index.query.QueryShardContext;
3132
import org.elasticsearch.test.ESSingleNodeTestCase;
3233

@@ -259,6 +260,16 @@ public void testUnmappedBoolean() throws Exception {
259260
}
260261
}
261262

263+
public void testTypeFieldDeprecation() {
264+
IndexService indexService = createIndex("index", Settings.EMPTY, "type");
265+
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
266+
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L, null);
267+
268+
ValuesSourceConfig<ValuesSource.Bytes> config = ValuesSourceConfig.resolve(
269+
context, null, TypeFieldMapper.NAME, null, null, null, null);
270+
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
271+
}
272+
}
262273

263274
public void testFieldAlias() throws Exception {
264275
IndexService indexService = createIndex("index", Settings.EMPTY, "type",

0 commit comments

Comments
 (0)