mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 05:15:04 +00:00
Deprecate _type from LeafDocLookup (#37491)
* Deprecate _type from LeafDocLookup * Response to PR comments. * Response to PR comments.
This commit is contained in:
parent
0b5af276a8
commit
3d8c04659c
@ -18,9 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.elasticsearch.search.lookup;
|
package org.elasticsearch.search.lookup;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.elasticsearch.ExceptionsHelper;
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldData;
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
@ -38,6 +40,12 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class LeafDocLookup implements Map<String, ScriptDocValues<?>> {
|
public class LeafDocLookup implements Map<String, ScriptDocValues<?>> {
|
||||||
|
|
||||||
|
private static final DeprecationLogger DEPRECATION_LOGGER
|
||||||
|
= new DeprecationLogger(LogManager.getLogger(LeafDocLookup.class));
|
||||||
|
static final String TYPES_DEPRECATION_KEY = "type-field-doc-lookup";
|
||||||
|
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 Map<String, ScriptDocValues<?>> localCacheFieldData = new HashMap<>(4);
|
||||||
|
|
||||||
private final MapperService mapperService;
|
private final MapperService mapperService;
|
||||||
@ -72,6 +80,10 @@ public class LeafDocLookup implements Map<String, ScriptDocValues<?>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptDocValues<?> get(Object key) {
|
public ScriptDocValues<?> get(Object key) {
|
||||||
|
// deprecate _type
|
||||||
|
if ("_type".equals(key)) {
|
||||||
|
DEPRECATION_LOGGER.deprecatedAndMaybeLog(TYPES_DEPRECATION_KEY, TYPES_DEPRECATION_MESSAGE);
|
||||||
|
}
|
||||||
// assume its a string...
|
// assume its a string...
|
||||||
String fieldName = key.toString();
|
String fieldName = key.toString();
|
||||||
ScriptDocValues<?> scriptValues = localCacheFieldData.get(fieldName);
|
ScriptDocValues<?> scriptValues = localCacheFieldData.get(fieldName);
|
||||||
|
@ -26,6 +26,7 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
|
import static org.elasticsearch.search.lookup.LeafDocLookup.TYPES_DEPRECATION_MESSAGE;
|
||||||
import static org.mockito.AdditionalAnswers.returnsFirstArg;
|
import static org.mockito.AdditionalAnswers.returnsFirstArg;
|
||||||
import static org.mockito.Matchers.anyObject;
|
import static org.mockito.Matchers.anyObject;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@ -45,6 +46,7 @@ public class LeafDocLookupTests extends ESTestCase {
|
|||||||
when(fieldType.valueForDisplay(anyObject())).then(returnsFirstArg());
|
when(fieldType.valueForDisplay(anyObject())).then(returnsFirstArg());
|
||||||
|
|
||||||
MapperService mapperService = mock(MapperService.class);
|
MapperService mapperService = mock(MapperService.class);
|
||||||
|
when(mapperService.fullName("_type")).thenReturn(fieldType);
|
||||||
when(mapperService.fullName("field")).thenReturn(fieldType);
|
when(mapperService.fullName("field")).thenReturn(fieldType);
|
||||||
when(mapperService.fullName("alias")).thenReturn(fieldType);
|
when(mapperService.fullName("alias")).thenReturn(fieldType);
|
||||||
|
|
||||||
@ -72,4 +74,10 @@ public class LeafDocLookupTests extends ESTestCase {
|
|||||||
ScriptDocValues<?> fetchedDocValues = docLookup.get("alias");
|
ScriptDocValues<?> fetchedDocValues = docLookup.get("alias");
|
||||||
assertEquals(docValues, fetchedDocValues);
|
assertEquals(docValues, fetchedDocValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testTypesDeprecation() {
|
||||||
|
ScriptDocValues<?> fetchedDocValues = docLookup.get("_type");
|
||||||
|
assertEquals(docValues, fetchedDocValues);
|
||||||
|
assertWarnings(TYPES_DEPRECATION_MESSAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user