Deprecate uses of _type as a field name in queries (#36503)
This commit is contained in:
parent
b5d532f9e3
commit
d40037c91e
|
@ -823,10 +823,9 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// 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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.client.Request;
|
|||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.index.mapper.TypeFieldMapper;
|
||||
import org.elasticsearch.rest.action.document.RestGetAction;
|
||||
import org.elasticsearch.rest.action.search.RestExplainAction;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -572,7 +573,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
|||
|
||||
Request explainRequest = new Request("GET", "/" + index + "/" + type + "/" + id + "/_explain");
|
||||
explainRequest.setJsonEntity("{ \"query\": { \"match_all\" : {} }}");
|
||||
explainRequest.setOptions(expectWarnings(RestExplainAction.TYPES_DEPRECATION_MESSAGE));
|
||||
explainRequest.setOptions(
|
||||
expectWarnings(RestExplainAction.TYPES_DEPRECATION_MESSAGE, TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE));
|
||||
String explanation = toStr(client().performRequest(explainRequest));
|
||||
assertFalse("Could not find payload boost in explanation\n" + explanation, explanation.contains("payloadBoost"));
|
||||
|
||||
|
|
|
@ -90,9 +90,11 @@ public class TypeFieldMapper extends MetadataFieldMapper {
|
|||
}
|
||||
}
|
||||
|
||||
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] Referring to types within search queries is deprecated, filter on a field instead.";
|
||||
|
||||
TypeFieldType() {
|
||||
}
|
||||
|
@ -124,6 +126,7 @@ public class TypeFieldMapper extends MetadataFieldMapper {
|
|||
|
||||
@Override
|
||||
public Query existsQuery(QueryShardContext context) {
|
||||
deprecationLogger.deprecatedAndMaybeLog("exists_query_with_type_field", TYPES_DEPRECATION_MESSAGE);
|
||||
return new MatchAllDocsQuery();
|
||||
}
|
||||
|
||||
|
@ -134,6 +137,7 @@ public class TypeFieldMapper extends MetadataFieldMapper {
|
|||
|
||||
@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 +159,7 @@ public class TypeFieldMapper extends MetadataFieldMapper {
|
|||
|
||||
@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) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.common.logging.DeprecationLogger;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.TypeFieldMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
@ -127,7 +128,7 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
|||
|
||||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
deprecationLogger.deprecated("The [type] query is deprecated, filter on a field instead.");
|
||||
deprecationLogger.deprecatedAndMaybeLog("type_query", TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
|
||||
//LUCENE 4 UPGRADE document mapper should use bytesref as well?
|
||||
DocumentMapper documentMapper = context.getMapperService().documentMapper(type);
|
||||
if (documentMapper == null) {
|
||||
|
|
|
@ -81,6 +81,29 @@ public class TypeFieldTypeTests extends FieldTypeTestCase {
|
|||
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);
|
||||
DocumentMapper mapper = Mockito.mock(DocumentMapper.class);
|
||||
Mockito.when(context.getMapperService()).thenReturn(mapperService);
|
||||
Mockito.when(mapperService.documentMapper()).thenReturn(mapper);
|
||||
Mockito.when(mapper.type()).thenReturn("my_type");
|
||||
|
||||
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 {
|
||||
|
|
|
@ -75,12 +75,12 @@ public class TypeQueryBuilderTests extends AbstractQueryTestCase<TypeQueryBuilde
|
|||
@Override
|
||||
public void testToQuery() throws IOException {
|
||||
super.testToQuery();
|
||||
assertWarnings("The [type] query is deprecated, filter on a field instead.");
|
||||
assertWarnings(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(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue