Skip to content
Merged
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: 0 additions & 5 deletions docs/changelog/121914.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,150 +74,3 @@ teardown:
- match: { _source.bytes_source_field: "1kb" }
- match: { _source.conditional_field: "bar" }
- is_false: _source.bytes_target_field

---
"Test conditional processor with fields API":
- do:
ingest.put_pipeline:
id: "my_pipeline"
body:
description: "_description"
processors:
- set:
if: "field('get.field').get('') == 'one'"
field: "one"
value: 1
- set:
if: "field('get.field').get('') == 'two'"
field: "missing"
value: "missing"
- set:
if: " /* avoid yaml stash */ $('get.field', 'one') == 'one'"
field: "dollar"
value: true
- set:
if: "field('missing.field').get('fallback') == 'fallback'"
field: "fallback"
value: "fallback"
- set:
if: "field('nested.array.get.with.index.field').get(1, null) == 'two'"
field: "two"
value: 2
- set:
if: "field('getName.field').getName() == 'getName.field'"
field: "three"
value: 3
- set:
if: "field('existing.field').exists()"
field: "four"
value: 4
- set:
if: "!field('empty.field').isEmpty()"
field: "missing"
value: "missing"
- set:
if: "field('size.field').size() == 2"
field: "five"
value: 5
- set:
if: >
def iterator = field('iterator.field').iterator();
def sum = 0;
while (iterator.hasNext()) {
sum += iterator.next();
}
return sum == 6;
field: "six"
value: 6
- set:
if: "field('hasValue.field').hasValue(v -> v == 'two')"
field: "seven"
value: 7
- match: { acknowledged: true }

- do:
index:
index: test
id: "1"
pipeline: "my_pipeline"
body:
get.field: "one"
nested:
array:
get.with.index.field: ["one", "two", "three"]
getName.field: "my_name"
existing.field: "indeed"
empty.field: []
size.field: ["one", "two"]
iterator.field: [1, 2, 3]
hasValue.field: ["one", "two", "three"]

- do:
get:
index: test
id: "1"
- match: { _source.get\.field: "one" }
- match: { _source.one: 1 }
- is_false: _source.missing
- is_true: _source.dollar
- match: { _source.fallback: "fallback" }
- match: { _source.nested.array.get\.with\.index\.field: ["one", "two", "three"] }
- match: { _source.two: 2 }
- match: { _source.three: 3 }
- match: { _source.four: 4 }
- match: { _source.five: 5 }
- match: { _source.six: 6 }
- match: { _source.seven: 7 }

---
"Test fields iterator is unmodifiable":
- do:
ingest.put_pipeline:
id: "my_pipeline"
body:
description: "_description"
processors:
- set:
if: >
def iterator = field('iterator.field').iterator();
def sum = 0;
while (iterator.hasNext()) {
sum += iterator.next();
iterator.remove();
}
return sum == 6;
field: "sum"
value: 6
- match: { acknowledged: true }

- do:
index:
index: test
id: "1"
pipeline: "my_pipeline"
body:
test.field: [1, 2, 3]
- match: { error: null }

- do:
index:
index: test
id: "2"
pipeline: "my_pipeline"
body:
iterator.field: [1, 2, 3]
catch: bad_request
- length: { error.root_cause: 1 }

- do:
get:
index: test
id: "1"
- match: { _source.test\.field: [1, 2, 3] }
- is_false: _source.sum

- do:
get:
index: test
id: "2"
catch: missing
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ class org.elasticsearch.script.IngestScript {
}

class org.elasticsearch.script.field.WriteField {
String getName()
boolean exists()
WriteField move(def)
WriteField overwrite(def)
void remove()
WriteField set(def)
WriteField append(def)
boolean isEmpty()
int size()
Iterator iterator()
def get(def)
def get(int, def)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class org.elasticsearch.script.ReindexScript {
}

class org.elasticsearch.script.field.WriteField {
String getName()
boolean exists()
WriteField move(def)
WriteField overwrite(def)
void remove()
WriteField set(def)
WriteField append(def)
boolean isEmpty()
int size()
Iterator iterator()
def get(def)
def get(int, def)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ class org.elasticsearch.script.UpdateScript {
}

class org.elasticsearch.script.field.WriteField {
String getName()
boolean exists()
WriteField move(def)
WriteField overwrite(def)
void remove()
WriteField set(def)
WriteField append(def)
boolean isEmpty()
int size()
Iterator iterator()
def get(def)
def get(int, def)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ class org.elasticsearch.script.UpdateByQueryScript {
}

class org.elasticsearch.script.field.WriteField {
String getName()
boolean exists()
WriteField move(def)
WriteField overwrite(def)
void remove()
WriteField set(def)
WriteField append(def)
boolean isEmpty()
int size()
Iterator iterator()
def get(def)
def get(int, def)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.script.CtxMapWrapper;
import org.elasticsearch.script.DynamicMap;
import org.elasticsearch.script.IngestConditionalScript;
import org.elasticsearch.script.Script;
Expand Down Expand Up @@ -58,7 +57,6 @@ public class ConditionalProcessor extends AbstractProcessor implements WrappingP
private final IngestMetric metric;
private final LongSupplier relativeTimeProvider;
private final IngestConditionalScript precompiledConditionScript;
private final CtxMapWrapper ctxMapWrapper;

ConditionalProcessor(String tag, String description, Script script, ScriptService scriptService, Processor processor) {
this(tag, description, script, scriptService, processor, System::nanoTime);
Expand All @@ -78,12 +76,11 @@ public class ConditionalProcessor extends AbstractProcessor implements WrappingP
this.processor = processor;
this.metric = new IngestMetric();
this.relativeTimeProvider = relativeTimeProvider;
this.ctxMapWrapper = new CtxMapWrapper();

try {
final IngestConditionalScript.Factory factory = scriptService.compile(script, IngestConditionalScript.CONTEXT);
if (ScriptType.INLINE.equals(script.getType())) {
precompiledConditionScript = factory.newInstance(script.getParams(), ctxMapWrapper);
precompiledConditionScript = factory.newInstance(script.getParams());
} else {
// stored script, so will have to compile at runtime
precompiledConditionScript = null;
Expand Down Expand Up @@ -147,14 +144,9 @@ boolean evaluate(IngestDocument ingestDocument) {
IngestConditionalScript script = precompiledConditionScript;
if (script == null) {
IngestConditionalScript.Factory factory = scriptService.compile(condition, IngestConditionalScript.CONTEXT);
script = factory.newInstance(condition.getParams(), ctxMapWrapper);
}
ctxMapWrapper.setCtxMap(new UnmodifiableIngestData(new DynamicMap(ingestDocument.getSourceAndMetadata(), FUNCTIONS)));
try {
return script.execute();
} finally {
ctxMapWrapper.clearCtxMap();
script = factory.newInstance(condition.getParams());
}
return script.execute(new UnmodifiableIngestData(new DynamicMap(ingestDocument.getSourceAndMetadata(), FUNCTIONS)));
}

public Processor getInnerProcessor() {
Expand Down
36 changes: 0 additions & 36 deletions server/src/main/java/org/elasticsearch/script/CtxMapWrapper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

/**
* A script used by {@link org.elasticsearch.ingest.ConditionalProcessor}.
* To properly expose the {@link SourceMapFieldScript#field(String)} API, make sure to provide a valid {@link CtxMap} before execution
* through the {@link CtxMapWrapper} passed to the constructor and make sure to clear it after use to avoid leaks.
*/
public abstract class IngestConditionalScript extends SourceMapFieldScript {
public abstract class IngestConditionalScript {

public static final String[] PARAMETERS = {};
public static final String[] PARAMETERS = { "ctx" };

/** The context used to compile {@link IngestConditionalScript} factories. */
public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>(
Expand All @@ -35,8 +33,7 @@ public abstract class IngestConditionalScript extends SourceMapFieldScript {
/** The generic runtime parameters for the script. */
private final Map<String, Object> params;

public IngestConditionalScript(Map<String, Object> params, CtxMapWrapper ctxMapWrapper) {
super(ctxMapWrapper);
public IngestConditionalScript(Map<String, Object> params) {
this.params = params;
}

Expand All @@ -45,9 +42,9 @@ public Map<String, Object> getParams() {
return params;
}

public abstract boolean execute();
public abstract boolean execute(Map<String, Object> ctx);

public interface Factory {
IngestConditionalScript newInstance(Map<String, Object> params, CtxMapWrapper ctxMapWrapper);
IngestConditionalScript newInstance(Map<String, Object> params);
}
}
Loading
Loading