Skip to content

Commit

Permalink
Deprecate the _type field in aggregations. (#37131)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani authored Jan 4, 2019
1 parent e40193a commit 0bac64f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
public class QueryShardContext extends QueryRewriteContext {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(QueryShardContext.class));
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using the _type field " +
"in queries is deprecated, prefer to filter on a field instead.";
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using the _type field " +
"in queries and aggregations is deprecated, prefer to use a field instead.";

private final ScriptService scriptService;
private final IndexSettings indexSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine.Searcher;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.mapper.TypeFieldMapper;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.test.ESSingleNodeTestCase;

Expand Down Expand Up @@ -259,6 +260,16 @@ public void testUnmappedBoolean() throws Exception {
}
}

public void testTypeFieldDeprecation() {
IndexService indexService = createIndex("index", Settings.EMPTY, "type");
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L, null);

ValuesSourceConfig<ValuesSource.Bytes> config = ValuesSourceConfig.resolve(
context, null, TypeFieldMapper.NAME, null, null, null, null);
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
}
}

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

0 comments on commit 0bac64f

Please sign in to comment.