-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate _type from LeafDocLookup #37491
Changes from 1 commit
3a88b40
5ee2158
e059650
18d3911
0dffccb
3b2f67b
f52a158
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ | |
*/ | ||
package org.elasticsearch.search.lookup; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.elasticsearch.ExceptionsHelper; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.index.fielddata.IndexFieldData; | ||
import org.elasticsearch.index.fielddata.ScriptDocValues; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
|
@@ -38,6 +40,11 @@ | |
|
||
public class LeafDocLookup implements Map<String, ScriptDocValues<?>> { | ||
|
||
private static final DeprecationLogger DEPRECATION_LOGGER | ||
= new DeprecationLogger(LogManager.getLogger(LeafDocLookup.class)); | ||
static final String TYPES_DEPRECATION_MESSAGE = | ||
"[types removal] Looking up doc types in scripts is deprecated."; | ||
|
||
private final Map<String, ScriptDocValues<?>> localCacheFieldData = new HashMap<>(4); | ||
|
||
private final MapperService mapperService; | ||
|
@@ -72,6 +79,10 @@ public void setDocument(int docId) { | |
|
||
@Override | ||
public ScriptDocValues<?> get(Object key) { | ||
// deprecate _type | ||
if ("_type".equals(key)) { | ||
DEPRECATION_LOGGER.deprecated(TYPES_DEPRECATION_MESSAGE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be deprecatedAndMaybeLog There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
} | ||
// assume its a string... | ||
String fieldName = key.toString(); | ||
ScriptDocValues<?> scriptValues = localCacheFieldData.get(fieldName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ public void setUp() throws Exception { | |
when(fieldType.valueForDisplay(anyObject())).then(returnsFirstArg()); | ||
|
||
MapperService mapperService = mock(MapperService.class); | ||
when(mapperService.fullName("_type")).thenReturn(fieldType); | ||
when(mapperService.fullName("field")).thenReturn(fieldType); | ||
when(mapperService.fullName("alias")).thenReturn(fieldType); | ||
|
||
|
@@ -72,4 +73,10 @@ public void testLookupWithFieldAlias() { | |
ScriptDocValues<?> fetchedDocValues = docLookup.get("alias"); | ||
assertEquals(docValues, fetchedDocValues); | ||
} | ||
|
||
public void testTypesDeprecation() { | ||
ScriptDocValues<?> fetchedDocValues = docLookup.get("_type"); | ||
assertEquals(docValues, fetchedDocValues); | ||
assertWarnings("[types removal] Looking up doc types in scripts is deprecated."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this warning will be written out, then no need for a package private constant in leaf doc lookup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use
deprecatedAndMaybeLog
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) already done. @rjernst mentioned the same thing.