Skip to content

Commit 3d8c046

Browse files
authored
Deprecate _type from LeafDocLookup (#37491)
* Deprecate _type from LeafDocLookup * Response to PR comments. * Response to PR comments.
1 parent 0b5af27 commit 3d8c046

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

server/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
*/
1919
package org.elasticsearch.search.lookup;
2020

21+
import org.apache.logging.log4j.LogManager;
2122
import org.apache.lucene.index.LeafReaderContext;
2223
import org.elasticsearch.ExceptionsHelper;
2324
import org.elasticsearch.common.Nullable;
25+
import org.elasticsearch.common.logging.DeprecationLogger;
2426
import org.elasticsearch.index.fielddata.IndexFieldData;
2527
import org.elasticsearch.index.fielddata.ScriptDocValues;
2628
import org.elasticsearch.index.mapper.MappedFieldType;
@@ -38,6 +40,12 @@
3840

3941
public class LeafDocLookup implements Map<String, ScriptDocValues<?>> {
4042

43+
private static final DeprecationLogger DEPRECATION_LOGGER
44+
= new DeprecationLogger(LogManager.getLogger(LeafDocLookup.class));
45+
static final String TYPES_DEPRECATION_KEY = "type-field-doc-lookup";
46+
static final String TYPES_DEPRECATION_MESSAGE =
47+
"[types removal] Looking up doc types in scripts is deprecated.";
48+
4149
private final Map<String, ScriptDocValues<?>> localCacheFieldData = new HashMap<>(4);
4250

4351
private final MapperService mapperService;
@@ -72,6 +80,10 @@ public void setDocument(int docId) {
7280

7381
@Override
7482
public ScriptDocValues<?> get(Object key) {
83+
// deprecate _type
84+
if ("_type".equals(key)) {
85+
DEPRECATION_LOGGER.deprecatedAndMaybeLog(TYPES_DEPRECATION_KEY, TYPES_DEPRECATION_MESSAGE);
86+
}
7587
// assume its a string...
7688
String fieldName = key.toString();
7789
ScriptDocValues<?> scriptValues = localCacheFieldData.get(fieldName);

server/src/test/java/org/elasticsearch/search/lookup/LeafDocLookupTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.test.ESTestCase;
2727
import org.junit.Before;
2828

29+
import static org.elasticsearch.search.lookup.LeafDocLookup.TYPES_DEPRECATION_MESSAGE;
2930
import static org.mockito.AdditionalAnswers.returnsFirstArg;
3031
import static org.mockito.Matchers.anyObject;
3132
import static org.mockito.Mockito.doReturn;
@@ -45,6 +46,7 @@ public void setUp() throws Exception {
4546
when(fieldType.valueForDisplay(anyObject())).then(returnsFirstArg());
4647

4748
MapperService mapperService = mock(MapperService.class);
49+
when(mapperService.fullName("_type")).thenReturn(fieldType);
4850
when(mapperService.fullName("field")).thenReturn(fieldType);
4951
when(mapperService.fullName("alias")).thenReturn(fieldType);
5052

@@ -72,4 +74,10 @@ public void testLookupWithFieldAlias() {
7274
ScriptDocValues<?> fetchedDocValues = docLookup.get("alias");
7375
assertEquals(docValues, fetchedDocValues);
7476
}
77+
78+
public void testTypesDeprecation() {
79+
ScriptDocValues<?> fetchedDocValues = docLookup.get("_type");
80+
assertEquals(docValues, fetchedDocValues);
81+
assertWarnings(TYPES_DEPRECATION_MESSAGE);
82+
}
7583
}

0 commit comments

Comments
 (0)