Deprecate the _type field in aggregations. (#37131)

This commit is contained in:
Julie Tibshirani 2019-01-04 13:05:52 -08:00 committed by GitHub
parent e40193ae66
commit 0bac64fbd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -75,8 +75,8 @@ import static java.util.Collections.unmodifiableMap;
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;

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.settings.Settings;
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;
@ -259,6 +260,16 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
}
}
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",