Runtime fields: rename emitValue function to emit (#62191)

We decided to shorten the emitValue function to emit, given that emit is self-explanatory.

Relates to #59332
This commit is contained in:
Luca Cavanna 2020-09-10 16:06:17 +02:00
parent 25db5acb0d
commit cd9774d8cb
36 changed files with 129 additions and 129 deletions

View File

@ -200,17 +200,17 @@ public class CoreTestsWithRuntimeFieldsIT extends ESClientYamlSuiteTestCase {
private static final Map<String, String> PAINLESS_TO_EMIT = org.elasticsearch.common.collect.Map.of(
BooleanFieldMapper.CONTENT_TYPE,
"emitValue(parse(value));",
"emit(parse(value));",
DateFieldMapper.CONTENT_TYPE,
"emitValue(parse(value.toString()));",
"emit(parse(value.toString()));",
NumberType.DOUBLE.typeName(),
"emitValue(value instanceof Number ? ((Number) value).doubleValue() : Double.parseDouble(value.toString()));",
"emit(value instanceof Number ? ((Number) value).doubleValue() : Double.parseDouble(value.toString()));",
KeywordFieldMapper.CONTENT_TYPE,
"emitValue(value.toString());",
"emit(value.toString());",
IpFieldMapper.CONTENT_TYPE,
"emitValue(value.toString());",
"emit(value.toString());",
NumberType.LONG.typeName(),
"emitValue(value instanceof Number ? ((Number) value).longValue() : Long.parseLong(value.toString()));"
"emit(value instanceof Number ? ((Number) value).longValue() : Long.parseLong(value.toString()));"
);
private static final ExecutableSection ADD_TEMPLATE = new ExecutableSection() {

View File

@ -73,7 +73,7 @@ public class PermissionsIT extends ESRestTestCase {
+ " \"year\" : {\n"
+ " \"type\" : \"runtime\", \n"
+ " \"runtime_type\" : \"keyword\",\n"
+ " \"script\" : \"emitValue(doc['date'].value.substring(0,4))\"\n"
+ " \"script\" : \"emit(doc['date'].value.substring(0,4))\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
@ -115,7 +115,7 @@ public class PermissionsIT extends ESRestTestCase {
+ " \"hidden_values_count\" : {\n"
+ " \"type\" : \"runtime\", \n"
+ " \"runtime_type\" : \"long\",\n"
+ " \"script\" : \"emitValue(doc['hidden'].size())\"\n"
+ " \"script\" : \"emit(doc['hidden'].size())\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
@ -164,7 +164,7 @@ public class PermissionsIT extends ESRestTestCase {
+ " \"year\" : {\n"
+ " \"type\" : \"runtime\", \n"
+ " \"runtime_type\" : \"keyword\",\n"
+ " \"script\" : \"emitValue(doc['date'].value.substring(0,4))\"\n"
+ " \"script\" : \"emit(doc['date'].value.substring(0,4))\"\n"
+ " }\n"
+ " }\n"
+ " }\n"

View File

@ -49,7 +49,7 @@ public abstract class AbstractLongScriptFieldScript extends AbstractScriptFieldS
return count;
}
protected final void emitValue(long v) {
protected final void emit(long v) {
checkMaxSize(count);
if (values.length < count + 1) {
values = ArrayUtil.grow(values, count + 1);

View File

@ -69,7 +69,7 @@ public abstract class BooleanScriptFieldScript extends AbstractScriptFieldScript
return falses;
}
protected final void emitValue(boolean v) {
protected final void emit(boolean v) {
if (v) {
trues++;
} else {
@ -81,15 +81,15 @@ public abstract class BooleanScriptFieldScript extends AbstractScriptFieldScript
return Booleans.parseBoolean(str.toString());
}
public static class EmitValue {
public static class Emit {
private final BooleanScriptFieldScript script;
public EmitValue(BooleanScriptFieldScript script) {
public Emit(BooleanScriptFieldScript script) {
this.script = script;
}
public void value(boolean v) {
script.emitValue(v);
script.emit(v);
}
}
}

View File

@ -58,15 +58,15 @@ public abstract class DateScriptFieldScript extends AbstractLongScriptFieldScrip
return millis;
}
public static class EmitValue {
public static class Emit {
private final DateScriptFieldScript script;
public EmitValue(DateScriptFieldScript script) {
public Emit(DateScriptFieldScript script) {
this.script = script;
}
public void emitValue(long v) {
script.emitValue(v);
public void emit(long v) {
script.emit(v);
}
}

View File

@ -71,7 +71,7 @@ public abstract class DoubleScriptFieldScript extends AbstractScriptFieldScript
return count;
}
protected final void emitValue(double v) {
protected final void emit(double v) {
checkMaxSize(count);
if (values.length < count + 1) {
values = ArrayUtil.grow(values, count + 1);
@ -79,15 +79,15 @@ public abstract class DoubleScriptFieldScript extends AbstractScriptFieldScript
values[count++] = v;
}
public static class EmitValue {
public static class Emit {
private final DoubleScriptFieldScript script;
public EmitValue(DoubleScriptFieldScript script) {
public Emit(DoubleScriptFieldScript script) {
this.script = script;
}
public void emitValue(double v) {
script.emitValue(v);
public void emit(double v) {
script.emit(v);
}
}
}

View File

@ -93,7 +93,7 @@ public abstract class IpScriptFieldScript extends AbstractScriptFieldScript {
return count;
}
protected final void emitValue(String v) {
protected final void emit(String v) {
checkMaxSize(count);
if (values.length < count + 1) {
values = ArrayUtil.grow(values, count + 1);
@ -101,15 +101,15 @@ public abstract class IpScriptFieldScript extends AbstractScriptFieldScript {
values[count++] = new BytesRef(InetAddressPoint.encode(InetAddresses.forString(v)));
}
public static class EmitValue {
public static class Emit {
private final IpScriptFieldScript script;
public EmitValue(IpScriptFieldScript script) {
public Emit(IpScriptFieldScript script) {
this.script = script;
}
public void emitValue(String v) {
script.emitValue(v);
public void emit(String v) {
script.emit(v);
}
}
}

View File

@ -39,15 +39,15 @@ public abstract class LongScriptFieldScript extends AbstractLongScriptFieldScrip
super(fieldName, params, searchLookup, ctx);
}
public static class EmitValue {
public static class Emit {
private final LongScriptFieldScript script;
public EmitValue(LongScriptFieldScript script) {
public Emit(LongScriptFieldScript script) {
this.script = script;
}
public void emitValue(long v) {
script.emitValue(v);
public void emit(long v) {
script.emit(v);
}
}
}

View File

@ -65,7 +65,7 @@ public abstract class StringScriptFieldScript extends AbstractScriptFieldScript
return results;
}
protected final void emitValue(String v) {
protected final void emit(String v) {
checkMaxSize(results.size());
chars += v.length();
if (chars > MAX_CHARS) {
@ -82,15 +82,15 @@ public abstract class StringScriptFieldScript extends AbstractScriptFieldScript
results.add(v);
}
public static class EmitValue {
public static class Emit {
private final StringScriptFieldScript script;
public EmitValue(StringScriptFieldScript script) {
public Emit(StringScriptFieldScript script) {
this.script = script;
}
public void emitValue(String v) {
script.emitValue(v);
public void emit(String v) {
script.emit(v);
}
}
}

View File

@ -13,8 +13,8 @@ class org.elasticsearch.xpack.runtimefields.BooleanScriptFieldScript$Factory @no
}
static_import {
# The `emitValue` callback to collect values for the field
void emitValue(org.elasticsearch.xpack.runtimefields.BooleanScriptFieldScript, boolean) bound_to org.elasticsearch.xpack.runtimefields.BooleanScriptFieldScript$EmitValue
# The `emit` callback to collect values for the field
void emit(org.elasticsearch.xpack.runtimefields.BooleanScriptFieldScript, boolean) bound_to org.elasticsearch.xpack.runtimefields.BooleanScriptFieldScript$Emit
# Parse a value from the source to a boolean
boolean parse(def) from_class org.elasticsearch.xpack.runtimefields.BooleanScriptFieldScript
}

View File

@ -13,8 +13,8 @@ class org.elasticsearch.xpack.runtimefields.DateScriptFieldScript$Factory @no_im
}
static_import {
# The `emitValue` callback to collect values for the field
void emitValue(org.elasticsearch.xpack.runtimefields.DateScriptFieldScript, long) bound_to org.elasticsearch.xpack.runtimefields.DateScriptFieldScript$EmitValue
# The `emit` callback to collect values for the field
void emit(org.elasticsearch.xpack.runtimefields.DateScriptFieldScript, long) bound_to org.elasticsearch.xpack.runtimefields.DateScriptFieldScript$Emit
# Parse a value from the source to millis since epoch
long parse(org.elasticsearch.xpack.runtimefields.DateScriptFieldScript, def) bound_to org.elasticsearch.xpack.runtimefields.DateScriptFieldScript$Parse
# Add an easy method to convert temporalAccessors to millis since epoch.

View File

@ -13,7 +13,7 @@ class org.elasticsearch.xpack.runtimefields.DoubleScriptFieldScript$Factory @no_
}
static_import {
# The `emitValue` callback to collect values for the field
void emitValue(org.elasticsearch.xpack.runtimefields.DoubleScriptFieldScript, double) bound_to org.elasticsearch.xpack.runtimefields.DoubleScriptFieldScript$EmitValue
# The `emit` callback to collect values for the field
void emit(org.elasticsearch.xpack.runtimefields.DoubleScriptFieldScript, double) bound_to org.elasticsearch.xpack.runtimefields.DoubleScriptFieldScript$Emit
}

View File

@ -13,6 +13,6 @@ class org.elasticsearch.xpack.runtimefields.IpScriptFieldScript$Factory @no_impo
}
static_import {
# The `emitValue` callback to collect values for the field
void emitValue(org.elasticsearch.xpack.runtimefields.IpScriptFieldScript, String) bound_to org.elasticsearch.xpack.runtimefields.IpScriptFieldScript$EmitValue
# The `emit` callback to collect values for the field
void emit(org.elasticsearch.xpack.runtimefields.IpScriptFieldScript, String) bound_to org.elasticsearch.xpack.runtimefields.IpScriptFieldScript$Emit
}

View File

@ -13,6 +13,6 @@ class org.elasticsearch.xpack.runtimefields.LongScriptFieldScript$Factory @no_im
}
static_import {
# The `emitValue` callback to collect values for the field
void emitValue(org.elasticsearch.xpack.runtimefields.LongScriptFieldScript, long) bound_to org.elasticsearch.xpack.runtimefields.LongScriptFieldScript$EmitValue
# The `emit` callback to collect values for the field
void emit(org.elasticsearch.xpack.runtimefields.LongScriptFieldScript, long) bound_to org.elasticsearch.xpack.runtimefields.LongScriptFieldScript$Emit
}

View File

@ -13,6 +13,6 @@ class org.elasticsearch.xpack.runtimefields.StringScriptFieldScript$Factory @no_
}
static_import {
# The `emitValue` callback to collect values for the field
void emitValue(org.elasticsearch.xpack.runtimefields.StringScriptFieldScript, String) bound_to org.elasticsearch.xpack.runtimefields.StringScriptFieldScript$EmitValue
# The `emit` callback to collect values for the field
void emit(org.elasticsearch.xpack.runtimefields.StringScriptFieldScript, String) bound_to org.elasticsearch.xpack.runtimefields.StringScriptFieldScript$Emit
}

View File

@ -28,7 +28,7 @@ public class BooleanScriptFieldScriptTests extends ScriptFieldScriptTestCase<Boo
) {
@Override
public void execute() {
emitValue(false);
emit(false);
}
};
@ -55,7 +55,7 @@ public class BooleanScriptFieldScriptTests extends ScriptFieldScriptTestCase<Boo
@Override
public void execute() {
for (int i = 0; i <= AbstractScriptFieldScript.MAX_VALUES * 1000; i++) {
emitValue(i % 2 == 0);
emit(i % 2 == 0);
}
}
};

View File

@ -31,7 +31,7 @@ public class DateScriptFieldScriptTests extends ScriptFieldScriptTestCase<DateSc
) {
@Override
public void execute() {
emitValue(1595431354874L);
emit(1595431354874L);
}
};
@ -59,7 +59,7 @@ public class DateScriptFieldScriptTests extends ScriptFieldScriptTestCase<DateSc
@Override
public void execute() {
for (int i = 0; i <= AbstractScriptFieldScript.MAX_VALUES; i++) {
emitValue(0);
emit(0);
}
}
};

View File

@ -29,7 +29,7 @@ public class DoubleScriptFieldScriptTests extends ScriptFieldScriptTestCase<Doub
) {
@Override
public void execute() {
emitValue(1.0);
emit(1.0);
}
};
@ -56,7 +56,7 @@ public class DoubleScriptFieldScriptTests extends ScriptFieldScriptTestCase<Doub
@Override
public void execute() {
for (int i = 0; i <= AbstractScriptFieldScript.MAX_VALUES; i++) {
emitValue(1.0);
emit(1.0);
}
}
};

View File

@ -29,7 +29,7 @@ public class IpScriptFieldScriptTests extends ScriptFieldScriptTestCase<IpScript
) {
@Override
public void execute() {
emitValue("192.168.0.1");
emit("192.168.0.1");
}
};
@ -56,7 +56,7 @@ public class IpScriptFieldScriptTests extends ScriptFieldScriptTestCase<IpScript
@Override
public void execute() {
for (int i = 0; i <= AbstractScriptFieldScript.MAX_VALUES; i++) {
emitValue("192.168.0.1");
emit("192.168.0.1");
}
}
};

View File

@ -29,7 +29,7 @@ public class LongScriptFieldScriptTests extends ScriptFieldScriptTestCase<LongSc
) {
@Override
public void execute() {
emitValue(1);
emit(1);
}
};
@ -56,7 +56,7 @@ public class LongScriptFieldScriptTests extends ScriptFieldScriptTestCase<LongSc
@Override
public void execute() {
for (int i = 0; i <= AbstractScriptFieldScript.MAX_VALUES; i++) {
emitValue(0);
emit(0);
}
}
};

View File

@ -29,7 +29,7 @@ public class StringScriptFieldScriptTests extends ScriptFieldScriptTestCase<Stri
) {
@Override
public void execute() {
emitValue("foo");
emit("foo");
}
};
@ -56,7 +56,7 @@ public class StringScriptFieldScriptTests extends ScriptFieldScriptTestCase<Stri
@Override
public void execute() {
for (int i = 0; i <= AbstractScriptFieldScript.MAX_VALUES; i++) {
emitValue("test");
emit("test");
}
}
};
@ -87,7 +87,7 @@ public class StringScriptFieldScriptTests extends ScriptFieldScriptTestCase<Stri
}
String bigString = big.toString();
for (int i = 0; i <= 4; i++) {
emitValue(bigString);
emit(bigString);
}
}
};

View File

@ -467,7 +467,7 @@ public class ScriptBooleanMappedFieldTypeTests extends AbstractNonTextScriptMapp
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(parse(foo));
emit(parse(foo));
}
}
};
@ -481,7 +481,7 @@ public class ScriptBooleanMappedFieldTypeTests extends AbstractNonTextScriptMapp
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue((Boolean) foo ^ ((Boolean) getParams().get("param")));
emit((Boolean) foo ^ ((Boolean) getParams().get("param")));
}
}
};

View File

@ -515,7 +515,7 @@ public class ScriptDateMappedFieldTypeTests extends AbstractNonTextScriptMappedF
public void execute() {
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
DateScriptFieldScript.Parse parse = new DateScriptFieldScript.Parse(this);
emitValue(parse.parse(timestamp));
emit(parse.parse(timestamp));
}
}
};
@ -533,7 +533,7 @@ public class ScriptDateMappedFieldTypeTests extends AbstractNonTextScriptMappedF
long epoch = (Long) timestamp;
ZonedDateTime dt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epoch), ZoneId.of("UTC"));
dt = dt.plus(((Number) params.get("days")).longValue(), ChronoUnit.DAYS);
emitValue(toEpochMilli(dt));
emit(toEpochMilli(dt));
}
}
};

View File

@ -299,7 +299,7 @@ public class ScriptDoubleMappedFieldTypeTests extends AbstractNonTextScriptMappe
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(((Number) foo).doubleValue());
emit(((Number) foo).doubleValue());
}
}
};
@ -308,7 +308,7 @@ public class ScriptDoubleMappedFieldTypeTests extends AbstractNonTextScriptMappe
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(((Number) foo).doubleValue() + ((Number) getParams().get("param")).doubleValue());
emit(((Number) foo).doubleValue() + ((Number) getParams().get("param")).doubleValue());
}
}
};

View File

@ -342,7 +342,7 @@ public class ScriptIpMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(foo.toString());
emit(foo.toString());
}
}
};
@ -351,7 +351,7 @@ public class ScriptIpMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(foo.toString() + getParams().get("param"));
emit(foo.toString() + getParams().get("param"));
}
}
};

View File

@ -383,7 +383,7 @@ public class ScriptKeywordMappedFieldTypeTests extends AbstractScriptMappedField
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(foo.toString());
emit(foo.toString());
}
}
};
@ -392,7 +392,7 @@ public class ScriptKeywordMappedFieldTypeTests extends AbstractScriptMappedField
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(foo.toString() + getParams().get("param").toString());
emit(foo.toString() + getParams().get("param").toString());
}
}
};

View File

@ -328,7 +328,7 @@ public class ScriptLongMappedFieldTypeTests extends AbstractNonTextScriptMappedF
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(((Number) foo).longValue());
emit(((Number) foo).longValue());
}
}
};
@ -337,7 +337,7 @@ public class ScriptLongMappedFieldTypeTests extends AbstractNonTextScriptMappedF
@Override
public void execute() {
for (Object foo : (List<?>) getSource().get("foo")) {
emitValue(((Number) foo).longValue() + ((Number) getParams().get("param")).longValue());
emit(((Number) foo).longValue() + ((Number) getParams().get("param")).longValue());
}
}
};
@ -348,7 +348,7 @@ public class ScriptLongMappedFieldTypeTests extends AbstractNonTextScriptMappedF
@Override
public void execute() {
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
emitValue(now - ((Number) timestamp).longValue());
emit(now - ((Number) timestamp).longValue());
}
}
};

View File

@ -95,7 +95,7 @@ public class LongScriptFieldDistanceFeatureQueryTests extends AbstractScriptFiel
@Override
public void execute() {
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
emitValue(((Number) timestamp).longValue());
emit(((Number) timestamp).longValue());
}
}
};

View File

@ -22,7 +22,7 @@ setup:
type: runtime
runtime_type: keyword
script: |
emitValue(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
# Test fetching from _source
day_of_week_from_source:
type: runtime
@ -30,7 +30,7 @@ setup:
script: |
Instant instant = Instant.ofEpochMilli(params._source.timestamp);
ZonedDateTime dt = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC"));
emitValue(dt.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ROOT));
emit(dt.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ROOT));
# Test fetching many values
day_of_week_letters:
type: runtime
@ -38,7 +38,7 @@ setup:
script: |
for (String dow: doc['day_of_week']) {
for (int i = 0; i < dow.length(); i++) {
emitValue(dow.charAt(i).toString());
emit(dow.charAt(i).toString());
}
}
prefixed_node:
@ -47,7 +47,7 @@ setup:
script:
source: |
for (String node : params._fields.node.values) {
emitValue(params.prefix + node);
emit(params.prefix + node);
}
params:
prefix: node_
@ -79,7 +79,7 @@ setup:
- match: {sensor.mappings.properties.day_of_week.runtime_type: keyword }
- match:
sensor.mappings.properties.day_of_week.script.source: |
emitValue(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
- match: {sensor.mappings.properties.day_of_week.script.lang: painless }
---
@ -95,7 +95,7 @@ setup:
runtime_type: keyword
script:
source: |
emitValue(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
lang: painless
meta: {}
@ -204,11 +204,11 @@ setup:
first_script:
type: runtime
runtime_type: keyword
script: emitValue(doc['users.first'].value)
script: emit(doc['users.first'].value)
last_script:
type: runtime
runtime_type: keyword
script: emitValue(doc['users.last'].value)
script: emit(doc['users.last'].value)
- do:
bulk:
index: test

View File

@ -23,7 +23,7 @@ setup:
script:
source: |
for (double v : doc['voltage']) {
emitValue((long)(v * params.multiplier));
emit((long)(v * params.multiplier));
}
params:
multiplier: 10
@ -33,7 +33,7 @@ setup:
runtime_type: long
script:
source: |
emitValue((long)(params._source.voltage * params.multiplier));
emit((long)(params._source.voltage * params.multiplier));
params:
multiplier: 10
# Test fetching many values
@ -45,7 +45,7 @@ setup:
for (long temperature : doc['temperature']) {
long t = temperature;
while (t != 0) {
emitValue(t % 10);
emit(t % 10);
t /= 10;
}
}
@ -56,7 +56,7 @@ setup:
script:
source: |
for (def dt : doc['timestamp']) {
emitValue(System.currentTimeMillis() - dt.toInstant().toEpochMilli());
emit(System.currentTimeMillis() - dt.toInstant().toEpochMilli());
}
- do:
@ -87,7 +87,7 @@ setup:
- match:
sensor.mappings.properties.voltage_times_ten.script.source: |
for (double v : doc['voltage']) {
emitValue((long)(v * params.multiplier));
emit((long)(v * params.multiplier));
}
- match: {sensor.mappings.properties.voltage_times_ten.script.params: {multiplier: 10} }
- match: {sensor.mappings.properties.voltage_times_ten.script.lang: painless }
@ -167,11 +167,11 @@ setup:
first_script:
type: runtime
runtime_type: long
script: emitValue(doc['users.first'].value.length())
script: emit(doc['users.first'].value.length())
last_script:
type: runtime
runtime_type: long
script: emitValue(doc['users.last'].value.length())
script: emit(doc['users.last'].value.length())
- do:
bulk:
index: test

View File

@ -23,7 +23,7 @@ setup:
script:
source: |
for (double v : doc['voltage']) {
emitValue(v / params.max);
emit(v / params.max);
}
params:
max: 5.8
@ -33,7 +33,7 @@ setup:
runtime_type: double
script:
source: |
emitValue(params._source.voltage / params.max);
emit(params._source.voltage / params.max);
params:
max: 5.8
# Test fetching many values
@ -45,7 +45,7 @@ setup:
for (double voltage : doc['voltage']) {
double v = voltage;
while (v > 1.2) {
emitValue(v);
emit(v);
v = Math.sqrt(v);
}
}
@ -78,7 +78,7 @@ setup:
- match:
sensor.mappings.properties.voltage_percent.script.source: |
for (double v : doc['voltage']) {
emitValue(v / params.max);
emit(v / params.max);
}
- match: {sensor.mappings.properties.voltage_percent.script.params: {max: 5.8} }
- match: {sensor.mappings.properties.voltage_percent.script.lang: painless }

View File

@ -23,7 +23,7 @@ setup:
script:
source: |
for (def dt : doc['timestamp']) {
emitValue(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS)));
}
params:
days: 1
@ -35,7 +35,7 @@ setup:
source: |
Instant instant = Instant.ofEpochMilli(parse(params._source.timestamp));
ZonedDateTime dt = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC"));
emitValue(toEpochMilli(dt.plus(1, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(1, ChronoUnit.DAYS)));
# Test returning millis
the_past:
type: runtime
@ -43,7 +43,7 @@ setup:
script:
source: |
for (def dt : doc['timestamp']) {
emitValue(dt.toInstant().toEpochMilli() - 1000);
emit(dt.toInstant().toEpochMilli() - 1000);
}
# Test fetching many values
all_week:
@ -53,7 +53,7 @@ setup:
source: |
for (def dt : doc['timestamp']) {
for (int i = 0; i < 7; i++) {
emitValue(toEpochMilli(dt.plus(i, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(i, ChronoUnit.DAYS)));
}
}
# Test format parameter
@ -63,7 +63,7 @@ setup:
format: yyyy-MM-dd
script: |
for (def dt : doc['timestamp']) {
emitValue(toEpochMilli(dt.plus(1, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(1, ChronoUnit.DAYS)));
}
- do:
@ -94,7 +94,7 @@ setup:
- match:
sensor.mappings.properties.tomorrow.script.source: |
for (def dt : doc['timestamp']) {
emitValue(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS)));
}
- match: {sensor.mappings.properties.tomorrow.script.params: {days: 1} }
- match: {sensor.mappings.properties.tomorrow.script.lang: painless }
@ -104,7 +104,7 @@ setup:
- match:
sensor.mappings.properties.formatted_tomorrow.script.source: |
for (def dt : doc['timestamp']) {
emitValue(toEpochMilli(dt.plus(1, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(1, ChronoUnit.DAYS)));
}
- match: {sensor.mappings.properties.formatted_tomorrow.script.lang: painless }
- match: {sensor.mappings.properties.formatted_tomorrow.format: yyyy-MM-dd }

View File

@ -20,7 +20,7 @@ setup:
source: |
String m = doc["message"].value;
int end = m.indexOf(" ");
emitValue(m.substring(0, end));
emit(m.substring(0, end));
# Test fetching from _source
ip_from_source:
type: runtime
@ -29,7 +29,7 @@ setup:
source: |
String m = params._source.message;
int end = m.indexOf(" ");
emitValue(m.substring(0, end));
emit(m.substring(0, end));
# Test emitting many values
ip_many:
type: runtime
@ -41,7 +41,7 @@ setup:
end = m.lastIndexOf(".", end);
String stem = m.substring(0, end + 1);
for (int i = 0; i < 5; i++) {
emitValue(stem + i);
emit(stem + i);
}
- do:
bulk:
@ -73,7 +73,7 @@ setup:
http_logs.mappings.properties.ip.script.source: |
String m = doc["message"].value;
int end = m.indexOf(" ");
emitValue(m.substring(0, end));
emit(m.substring(0, end));
- match: {http_logs.mappings.properties.ip.script.lang: painless }
---

View File

@ -23,7 +23,7 @@ setup:
script:
source: |
for (def v : doc['voltage']) {
emitValue(v >= params.min_v);
emit(v >= params.min_v);
}
params:
min_v: 5.0
@ -33,7 +33,7 @@ setup:
runtime_type: boolean
script:
source: |
emitValue(params._source.voltage >= 5.0);
emit(params._source.voltage >= 5.0);
# Test many booleans
big_vals:
type: runtime
@ -41,10 +41,10 @@ setup:
script:
source: |
for (def v : doc['temperature']) {
emitValue(v >= 200);
emit(v >= 200);
}
for (def v : doc['voltage']) {
emitValue(v >= 5.0);
emit(v >= 5.0);
}
- do:
@ -75,7 +75,7 @@ setup:
- match:
sensor.mappings.properties.over_v.script.source: |
for (def v : doc['voltage']) {
emitValue(v >= params.min_v);
emit(v >= params.min_v);
}
- match: {sensor.mappings.properties.over_v.script.params: {min_v: 5.0} }
- match: {sensor.mappings.properties.over_v.script.lang: painless }

View File

@ -17,14 +17,14 @@ setup:
type: runtime
runtime_type: keyword
script: |
emitValue(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT));
tomorrow:
type: runtime
runtime_type: date
script:
source: |
for (def dt : doc['timestamp']) {
emitValue(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS)));
emit(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS)));
}
params:
days: 1
@ -36,7 +36,7 @@ setup:
script:
source: |
for (double v : doc['voltage']) {
emitValue((long)(v * params.multiplier));
emit((long)(v * params.multiplier));
}
params:
multiplier: 10
@ -46,7 +46,7 @@ setup:
script:
source: |
for (double v : doc['voltage']) {
emitValue(v / params.max);
emit(v / params.max);
}
params:
max: 5.8
@ -57,14 +57,14 @@ setup:
source: |
String m = doc["message"].value;
int end = m.indexOf(" ");
emitValue(m.substring(0, end));
emit(m.substring(0, end));
over_v:
type: runtime
runtime_type: boolean
script:
source: |
for (def v : doc['voltage']) {
emitValue(v >= params.min_v);
emit(v >= params.min_v);
}
params:
min_v: 5.0

View File

@ -20,51 +20,51 @@ setup:
tight_loop:
type: runtime
runtime_type: keyword
script: emitValue(doc['tight_loop'].value)
script: emit(doc['tight_loop'].value)
loose_loop:
type: runtime
runtime_type: keyword
script: emitValue(doc['lla'].value)
script: emit(doc['lla'].value)
lla:
type: runtime
runtime_type: keyword
script: emitValue(doc['llb'].value)
script: emit(doc['llb'].value)
llb:
type: runtime
runtime_type: keyword
script: emitValue(doc['llc'].value)
script: emit(doc['llc'].value)
llc:
type: runtime
runtime_type: keyword
script: emitValue(doc['loose_loop'].value)
script: emit(doc['loose_loop'].value)
refs:
type: runtime
runtime_type: keyword
script: emitValue(doc['over_max_depth_2'].value + doc['over_max_depth_3'].value + doc['over_max_depth_4'].value + doc['over_max_depth_5'].value + doc['node'].value)
script: emit(doc['over_max_depth_2'].value + doc['over_max_depth_3'].value + doc['over_max_depth_4'].value + doc['over_max_depth_5'].value + doc['node'].value)
over_max_depth:
type: runtime
runtime_type: keyword
script: emitValue(doc['over_max_depth_1'].value)
script: emit(doc['over_max_depth_1'].value)
over_max_depth_1:
type: runtime
runtime_type: keyword
script: emitValue(doc['over_max_depth_2'].value)
script: emit(doc['over_max_depth_2'].value)
over_max_depth_2:
type: runtime
runtime_type: keyword
script: emitValue(doc['over_max_depth_3'].value)
script: emit(doc['over_max_depth_3'].value)
over_max_depth_3:
type: runtime
runtime_type: keyword
script: emitValue(doc['over_max_depth_4'].value)
script: emit(doc['over_max_depth_4'].value)
over_max_depth_4:
type: runtime
runtime_type: keyword
script: emitValue(doc['over_max_depth_5'].value)
script: emit(doc['over_max_depth_5'].value)
over_max_depth_5:
type: runtime
runtime_type: keyword
script: emitValue('test')
script: emit('test')
- do:
bulk: