Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/134851.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 134851
summary: Remove ingest conditionals `_type` deprecation warning
area: Ingest Node
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

package org.elasticsearch.ingest;

import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.script.DynamicMap;
import org.elasticsearch.script.IngestConditionalScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptException;
Expand All @@ -28,7 +25,6 @@
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.LongSupplier;
import java.util.stream.Collectors;

Expand All @@ -39,16 +35,6 @@
*/
public class ConditionalProcessor extends AbstractProcessor implements WrappingProcessor {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DynamicMap.class);
private static final Map<String, Function<Object, Object>> FUNCTIONS = Map.of("_type", value -> {
deprecationLogger.warn(
DeprecationCategory.INDICES,
"conditional-processor__type",
"[types removal] Looking up doc types [_type] in scripts is deprecated."
);
return value;
});

static final String TYPE = "conditional";

private final Script condition;
Expand Down Expand Up @@ -144,10 +130,7 @@ boolean evaluate(IngestDocument ingestDocument) {
if (factory == null) {
factory = scriptService.compile(condition, IngestConditionalScript.CONTEXT);
}
return factory.newInstance(
condition.getParams(),
new UnmodifiableIngestData(new DynamicMap(ingestDocument.getSourceAndMetadata(), FUNCTIONS))
).execute();
return factory.newInstance(condition.getParams(), new UnmodifiableIngestData(ingestDocument.getSourceAndMetadata())).execute();
}

public Processor getInnerProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,55 +143,6 @@ public void testActsOnImmutableData() throws Exception {
assertMutatingCtxThrows(ctx -> ((List<Object>) ctx.get("listField")).remove("bar"));
}

public void testTypeDeprecation() throws Exception {

ScriptService scriptService = new ScriptService(
Settings.builder().build(),
Map.of(Script.DEFAULT_SCRIPT_LANG, new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, Map.of(scriptName, ctx -> {
ctx.get("_type");
return true;
}), Map.of())),
new HashMap<>(ScriptModule.CORE_CONTEXTS),
() -> 1L,
TestProjectResolvers.singleProject(randomProjectIdOrDefault())
);

LongSupplier relativeTimeProvider = mock(LongSupplier.class);
when(relativeTimeProvider.getAsLong()).thenReturn(0L, TimeUnit.MILLISECONDS.toNanos(1), 0L, TimeUnit.MILLISECONDS.toNanos(2));
ConditionalProcessor processor = new ConditionalProcessor(
randomAlphaOfLength(10),
"description",
new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, scriptName, Map.of()),
scriptService,
new Processor() {
@Override
public IngestDocument execute(final IngestDocument ingestDocument) {
return ingestDocument;
}

@Override
public String getType() {
return null;
}

@Override
public String getTag() {
return null;
}

@Override
public String getDescription() {
return null;
}
},
relativeTimeProvider
);

IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Map.of());
execProcessor(processor, ingestDocument, (result, e) -> {});
assertWarnings("[types removal] Looking up doc types [_type] in scripts is deprecated.");
}

public void testPrecompiledError() {
ScriptService scriptService = MockScriptService.singleContext(IngestConditionalScript.CONTEXT, code -> {
throw new ScriptException("bad script", new ParseException("error", 0), List.of(), "", "lang", null);
Expand Down