diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index ca15b20b163e4..2495cec7ce871 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -823,10 +823,9 @@ public void testReindex() throws Exception { // tag::reindex-request-conflicts request.setConflicts("proceed"); // <1> // end::reindex-request-conflicts - // tag::reindex-request-typeOrQuery - request.setSourceDocTypes("_doc"); // <1> - request.setSourceQuery(new TermQueryBuilder("user", "kimchy")); // <2> - // end::reindex-request-typeOrQuery + // tag::reindex-request-query + request.setSourceQuery(new TermQueryBuilder("user", "kimchy")); // <1> + // end::reindex-request-query // tag::reindex-request-size request.setSize(10); // <1> // end::reindex-request-size diff --git a/docs/java-rest/high-level/document/reindex.asciidoc b/docs/java-rest/high-level/document/reindex.asciidoc index 7d8876aa1269a..d78851f3d6a86 100644 --- a/docs/java-rest/high-level/document/reindex.asciidoc +++ b/docs/java-rest/high-level/document/reindex.asciidoc @@ -57,14 +57,13 @@ include-tagged::{doc-tests-file}[{api}-request-conflicts] -------------------------------------------------- <1> Set `proceed` on version conflict -You can limit the documents by adding a type to the source or by adding a query. +You can limit the documents by adding a query. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-typeOrQuery] +include-tagged::{doc-tests-file}[{api}-request-query] -------------------------------------------------- -<1> Only copy `doc` type -<2> Only copy documents which have field `user` set to `kimchy` +<1> Only copy documents which have field `user` set to `kimchy` It’s also possible to limit the number of processed documents by setting size. diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java index 03bd9f64ca4a1..ea547430475b6 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java @@ -90,9 +90,10 @@ public MetadataFieldMapper getDefault(MappedFieldType fieldType, ParserContext c } } - static final class TypeFieldType extends StringFieldType { + public static final class TypeFieldType extends StringFieldType { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(TypeFieldType.class)); + public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using [_type] as a field name in a query is deprecated."; TypeFieldType() { } @@ -124,6 +125,7 @@ public boolean isSearchable() { @Override public Query existsQuery(QueryShardContext context) { + deprecationLogger.deprecatedAndMaybeLog("exists_query_with_type_field", TYPES_DEPRECATION_MESSAGE); return new MatchAllDocsQuery(); } @@ -134,6 +136,7 @@ public Query termQuery(Object value, QueryShardContext context) { @Override public Query termsQuery(List values, QueryShardContext context) { + deprecationLogger.deprecatedAndMaybeLog("term_query_with_type_field", TYPES_DEPRECATION_MESSAGE); DocumentMapper mapper = context.getMapperService().documentMapper(); if (mapper == null) { return new MatchNoDocsQuery("No types"); @@ -155,9 +158,7 @@ public Query termsQuery(List values, QueryShardContext context) { @Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) { - deprecationLogger.deprecatedAndMaybeLog("range_single_type", - "Running [range] query on [_type] field for an index with a single type." - + " As types are deprecated, this functionality will be removed in future releases."); + deprecationLogger.deprecatedAndMaybeLog("range_query_with_type_field", TYPES_DEPRECATION_MESSAGE); Query result = new MatchAllDocsQuery(); String type = context.getMapperService().documentMapper().type(); if (type != null) { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java index 63c3e2c71c047..e311870235e38 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java @@ -81,8 +81,31 @@ public void testTermsQuery() throws Exception { Mockito.when(mapperService.documentMapper()).thenReturn(mapper); query = ft.termQuery("my_type", context); assertEquals(new MatchNoDocsQuery(), query); + assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE); } + public void testExistsQuery() { + QueryShardContext context = Mockito.mock(QueryShardContext.class); + TypeFieldMapper.TypeFieldType ft = new TypeFieldMapper.TypeFieldType(); + ft.setName(TypeFieldMapper.NAME); + ft.existsQuery(context); + assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE); + } + + public void testRangeQuery() { + QueryShardContext context = Mockito.mock(QueryShardContext.class); + MapperService mapperService = Mockito.mock(MapperService.class); + Mockito.when(mapperService.documentMapper()).thenReturn(null); + Mockito.when(context.getMapperService()).thenReturn(mapperService); + DocumentMapper mapper = Mockito.mock(DocumentMapper.class); + Mockito.when(mapper.type()).thenReturn("my_type"); + Mockito.when(mapperService.documentMapper()).thenReturn(mapper); + + TypeFieldMapper.TypeFieldType ft = new TypeFieldMapper.TypeFieldType(); + ft.setName(TypeFieldMapper.NAME); + ft.rangeQuery("type1", "type2", true, true, context); + assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE); + } static DirectoryReader openReaderWithNewType(String type, IndexWriter writer) throws IOException { Document doc = new Document(); diff --git a/server/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java index b75319b15c3e6..7ef9ef41bad61 100644 --- a/server/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java @@ -75,12 +75,18 @@ public void testFromJson() throws IOException { @Override public void testToQuery() throws IOException { super.testToQuery(); - assertWarnings("The [type] query is deprecated, filter on a field instead."); + assertWarnings( + "The [type] query is deprecated, filter on a field instead.", + TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE + ); } @Override public void testMustRewrite() throws IOException { super.testMustRewrite(); - assertWarnings("The [type] query is deprecated, filter on a field instead."); + assertWarnings( + "The [type] query is deprecated, filter on a field instead.", + TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE + ); } }