Replace property with field in IngestDocument
getPropertyValue => getFieldValue hasPropertyValue => hasFieldValue setPropertyValue => setFieldValue removeProperty => removeField
This commit is contained in:
parent
e15fa99ee3
commit
ec162c458e
|
@ -53,7 +53,7 @@ public final class IngestDocument {
|
||||||
* @return the value for the provided path if existing, null otherwise
|
* @return the value for the provided path if existing, null otherwise
|
||||||
* @throws IllegalArgumentException if the field is present but is not of the type provided as argument.
|
* @throws IllegalArgumentException if the field is present but is not of the type provided as argument.
|
||||||
*/
|
*/
|
||||||
public <T> T getPropertyValue(String path, Class<T> clazz) {
|
public <T> T getFieldValue(String path, Class<T> clazz) {
|
||||||
if (path == null || path.length() == 0) {
|
if (path == null || path.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -66,22 +66,22 @@ public final class IngestDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
String leafKey = pathElements[pathElements.length - 1];
|
String leafKey = pathElements[pathElements.length - 1];
|
||||||
Object property = innerMap.get(leafKey);
|
Object fieldValue = innerMap.get(leafKey);
|
||||||
if (property == null) {
|
if (fieldValue == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (clazz.isInstance(property)) {
|
if (clazz.isInstance(fieldValue)) {
|
||||||
return clazz.cast(property);
|
return clazz.cast(fieldValue);
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("field [" + path + "] of type [" + property.getClass().getName() + "] cannot be cast to [" + clazz.getName() + "]");
|
throw new IllegalArgumentException("field [" + path + "] of type [" + fieldValue.getClass().getName() + "] cannot be cast to [" + clazz.getName() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the document contains a value for the provided path
|
* Checks whether the document contains a value for the provided path
|
||||||
* @param path The path within the document in dot-notation
|
* @param path The path within the document in dot-notation
|
||||||
* @return true if the document contains a value for the property, false otherwise
|
* @return true if the document contains a value for the field, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean hasPropertyValue(String path) {
|
public boolean hasFieldValue(String path) {
|
||||||
if (path == null || path.length() == 0) {
|
if (path == null || path.length() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,10 @@ public final class IngestDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the property identified by the provided path
|
* Removes the field identified by the provided path
|
||||||
* @param path the path of the property to be removed
|
* @param path the path of the field to be removed
|
||||||
*/
|
*/
|
||||||
public void removeProperty(String path) {
|
public void removeField(String path) {
|
||||||
if (path == null || path.length() == 0) {
|
if (path == null || path.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ public final class IngestDocument {
|
||||||
* @param path The path within the document in dot-notation
|
* @param path The path within the document in dot-notation
|
||||||
* @param value The value to put in for the path key
|
* @param value The value to put in for the path key
|
||||||
*/
|
*/
|
||||||
public void setPropertyValue(String path, Object value) {
|
public void setFieldValue(String path, Object value) {
|
||||||
if (path == null || path.length() == 0) {
|
if (path == null || path.length() == 0) {
|
||||||
throw new IllegalArgumentException("cannot add null or empty field");
|
throw new IllegalArgumentException("cannot add null or empty field");
|
||||||
}
|
}
|
||||||
|
@ -175,8 +175,8 @@ public final class IngestDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the document. Should be used only for reading. Any change made to the returned map will
|
* Returns the document. Should be used only for reading. Any change made to the returned map will
|
||||||
* not be reflected to the modified flag. Modify the document instead using {@link #setPropertyValue(String, Object)}
|
* not be reflected to the modified flag. Modify the document instead using {@link #setFieldValue(String, Object)}
|
||||||
* and {@link #removeProperty(String)}
|
* and {@link #removeField(String)}
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> getSource() {
|
public Map<String, Object> getSource() {
|
||||||
return source;
|
return source;
|
||||||
|
|
|
@ -46,11 +46,11 @@ public abstract class AbstractStringProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public final void execute(IngestDocument document) {
|
public final void execute(IngestDocument document) {
|
||||||
for(String field : fields) {
|
for(String field : fields) {
|
||||||
String val = document.getPropertyValue(field, String.class);
|
String val = document.getFieldValue(field, String.class);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
throw new IllegalArgumentException("field [" + field + "] is null, cannot process it.");
|
throw new IllegalArgumentException("field [" + field + "] is null, cannot process it.");
|
||||||
}
|
}
|
||||||
document.setPropertyValue(field, process(val));
|
document.setFieldValue(field, process(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class AddProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for(Map.Entry<String, Object> entry : fields.entrySet()) {
|
for(Map.Entry<String, Object> entry : fields.entrySet()) {
|
||||||
document.setPropertyValue(entry.getKey(), entry.getValue());
|
document.setFieldValue(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class ConvertProcessor implements Processor {
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for(Map.Entry<String, Type> entry : fields.entrySet()) {
|
for(Map.Entry<String, Type> entry : fields.entrySet()) {
|
||||||
Type type = entry.getValue();
|
Type type = entry.getValue();
|
||||||
Object oldValue = document.getPropertyValue(entry.getKey(), Object.class);
|
Object oldValue = document.getFieldValue(entry.getKey(), Object.class);
|
||||||
Object newValue;
|
Object newValue;
|
||||||
if (oldValue == null) {
|
if (oldValue == null) {
|
||||||
throw new IllegalArgumentException("Field [" + entry.getKey() + "] is null, cannot be converted to type [" + type + "]");
|
throw new IllegalArgumentException("Field [" + entry.getKey() + "] is null, cannot be converted to type [" + type + "]");
|
||||||
|
@ -118,7 +118,7 @@ public class ConvertProcessor implements Processor {
|
||||||
} else {
|
} else {
|
||||||
newValue = type.convert(oldValue);
|
newValue = type.convert(oldValue);
|
||||||
}
|
}
|
||||||
document.setPropertyValue(entry.getKey(), newValue);
|
document.setFieldValue(entry.getKey(), newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public final class DateProcessor implements Processor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument ingestDocument) {
|
public void execute(IngestDocument ingestDocument) {
|
||||||
String value = ingestDocument.getPropertyValue(matchField, String.class);
|
String value = ingestDocument.getFieldValue(matchField, String.class);
|
||||||
// TODO(talevy): handle custom timestamp fields
|
// TODO(talevy): handle custom timestamp fields
|
||||||
|
|
||||||
DateTime dateTime = null;
|
DateTime dateTime = null;
|
||||||
|
@ -80,7 +80,7 @@ public final class DateProcessor implements Processor {
|
||||||
throw new IllegalArgumentException("unable to parse date [" + value + "]", lastException);
|
throw new IllegalArgumentException("unable to parse date [" + value + "]", lastException);
|
||||||
}
|
}
|
||||||
|
|
||||||
ingestDocument.setPropertyValue(targetField, ISODateTimeFormat.dateTime().print(dateTime));
|
ingestDocument.setFieldValue(targetField, ISODateTimeFormat.dateTime().print(dateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,7 +61,7 @@ public final class GeoIpProcessor implements Processor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument ingestDocument) {
|
public void execute(IngestDocument ingestDocument) {
|
||||||
String ip = ingestDocument.getPropertyValue(sourceField, String.class);
|
String ip = ingestDocument.getFieldValue(sourceField, String.class);
|
||||||
final InetAddress ipAddress;
|
final InetAddress ipAddress;
|
||||||
try {
|
try {
|
||||||
ipAddress = InetAddress.getByName(ip);
|
ipAddress = InetAddress.getByName(ip);
|
||||||
|
@ -88,7 +88,7 @@ public final class GeoIpProcessor implements Processor {
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType() + "]");
|
throw new IllegalStateException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType() + "]");
|
||||||
}
|
}
|
||||||
ingestDocument.setPropertyValue(targetField, geoData);
|
ingestDocument.setFieldValue(targetField, geoData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,12 +46,12 @@ public final class GrokProcessor implements Processor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument ingestDocument) {
|
public void execute(IngestDocument ingestDocument) {
|
||||||
Object field = ingestDocument.getPropertyValue(matchField, Object.class);
|
Object field = ingestDocument.getFieldValue(matchField, Object.class);
|
||||||
// TODO(talevy): handle invalid field types
|
// TODO(talevy): handle invalid field types
|
||||||
if (field instanceof String) {
|
if (field instanceof String) {
|
||||||
Map<String, Object> matches = grok.captures((String) field);
|
Map<String, Object> matches = grok.captures((String) field);
|
||||||
if (matches != null) {
|
if (matches != null) {
|
||||||
matches.forEach((k, v) -> ingestDocument.setPropertyValue(k, v));
|
matches.forEach((k, v) -> ingestDocument.setFieldValue(k, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,13 +51,13 @@ public class GsubProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for (GsubExpression gsubExpression : gsubExpressions) {
|
for (GsubExpression gsubExpression : gsubExpressions) {
|
||||||
String oldVal = document.getPropertyValue(gsubExpression.getFieldName(), String.class);
|
String oldVal = document.getFieldValue(gsubExpression.getFieldName(), String.class);
|
||||||
if (oldVal == null) {
|
if (oldVal == null) {
|
||||||
throw new IllegalArgumentException("field [" + gsubExpression.getFieldName() + "] is null, cannot match pattern.");
|
throw new IllegalArgumentException("field [" + gsubExpression.getFieldName() + "] is null, cannot match pattern.");
|
||||||
}
|
}
|
||||||
Matcher matcher = gsubExpression.getPattern().matcher(oldVal);
|
Matcher matcher = gsubExpression.getPattern().matcher(oldVal);
|
||||||
String newVal = matcher.replaceAll(gsubExpression.getReplacement());
|
String newVal = matcher.replaceAll(gsubExpression.getReplacement());
|
||||||
document.setPropertyValue(gsubExpression.getFieldName(), newVal);
|
document.setFieldValue(gsubExpression.getFieldName(), newVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,14 +50,14 @@ public class JoinProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for(Map.Entry<String, String> entry : fields.entrySet()) {
|
for(Map.Entry<String, String> entry : fields.entrySet()) {
|
||||||
List<?> list = document.getPropertyValue(entry.getKey(), List.class);
|
List<?> list = document.getFieldValue(entry.getKey(), List.class);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
throw new IllegalArgumentException("field [" + entry.getKey() + "] is null, cannot join.");
|
throw new IllegalArgumentException("field [" + entry.getKey() + "] is null, cannot join.");
|
||||||
}
|
}
|
||||||
String joined = list.stream()
|
String joined = list.stream()
|
||||||
.map(Object::toString)
|
.map(Object::toString)
|
||||||
.collect(Collectors.joining(entry.getValue()));
|
.collect(Collectors.joining(entry.getValue()));
|
||||||
document.setPropertyValue(entry.getKey(), joined);
|
document.setFieldValue(entry.getKey(), joined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class RemoveProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for(String field : fields) {
|
for(String field : fields) {
|
||||||
document.removeProperty(field);
|
document.removeField(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,13 @@ public class RenameProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for(Map.Entry<String, String> entry : fields.entrySet()) {
|
for(Map.Entry<String, String> entry : fields.entrySet()) {
|
||||||
if (document.hasPropertyValue(entry.getKey())) {
|
if (document.hasFieldValue(entry.getKey())) {
|
||||||
if (document.hasPropertyValue(entry.getKey()) == false) {
|
if (document.hasFieldValue(entry.getKey()) == false) {
|
||||||
throw new IllegalArgumentException("field [" + entry.getKey() + "] doesn't exist");
|
throw new IllegalArgumentException("field [" + entry.getKey() + "] doesn't exist");
|
||||||
}
|
}
|
||||||
Object oldValue = document.getPropertyValue(entry.getKey(), Object.class);
|
Object oldValue = document.getFieldValue(entry.getKey(), Object.class);
|
||||||
document.removeProperty(entry.getKey());
|
document.removeField(entry.getKey());
|
||||||
document.setPropertyValue(entry.getValue(), oldValue);
|
document.setFieldValue(entry.getValue(), oldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,11 @@ public class SplitProcessor implements Processor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument document) {
|
public void execute(IngestDocument document) {
|
||||||
for(Map.Entry<String, String> entry : fields.entrySet()) {
|
for(Map.Entry<String, String> entry : fields.entrySet()) {
|
||||||
String oldVal = document.getPropertyValue(entry.getKey(), String.class);
|
String oldVal = document.getFieldValue(entry.getKey(), String.class);
|
||||||
if (oldVal == null) {
|
if (oldVal == null) {
|
||||||
throw new IllegalArgumentException("field [" + entry.getKey() + "] is null, cannot split.");
|
throw new IllegalArgumentException("field [" + entry.getKey() + "] is null, cannot split.");
|
||||||
}
|
}
|
||||||
document.setPropertyValue(entry.getKey(), Arrays.asList(oldVal.split(entry.getValue())));
|
document.setFieldValue(entry.getKey(), Arrays.asList(oldVal.split(entry.getValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,91 +44,91 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
ingestDocument = new IngestDocument("index", "type", "id", document);
|
ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleGetPropertyValue() {
|
public void testSimpleGetFieldValue() {
|
||||||
assertThat(ingestDocument.getPropertyValue("foo", String.class), equalTo("bar"));
|
assertThat(ingestDocument.getFieldValue("foo", String.class), equalTo("bar"));
|
||||||
assertThat(ingestDocument.getPropertyValue("int", Integer.class), equalTo(123));
|
assertThat(ingestDocument.getFieldValue("int", Integer.class), equalTo(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetPropertyValueNullValue() {
|
public void testGetFieldValueNullValue() {
|
||||||
assertThat(ingestDocument.getPropertyValue("fizz.foo_null", Object.class), nullValue());
|
assertThat(ingestDocument.getFieldValue("fizz.foo_null", Object.class), nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleGetPropertyValueTypeMismatch() {
|
public void testSimpleGetFieldValueTypeMismatch() {
|
||||||
try {
|
try {
|
||||||
ingestDocument.getPropertyValue("int", String.class);
|
ingestDocument.getFieldValue("int", String.class);
|
||||||
fail("getProperty should have failed");
|
fail("getFieldValue should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("field [int] of type [java.lang.Integer] cannot be cast to [java.lang.String]"));
|
assertThat(e.getMessage(), equalTo("field [int] of type [java.lang.Integer] cannot be cast to [java.lang.String]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ingestDocument.getPropertyValue("foo", Integer.class);
|
ingestDocument.getFieldValue("foo", Integer.class);
|
||||||
fail("getProperty should have failed");
|
fail("getFieldValue should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("field [foo] of type [java.lang.String] cannot be cast to [java.lang.Integer]"));
|
assertThat(e.getMessage(), equalTo("field [foo] of type [java.lang.String] cannot be cast to [java.lang.Integer]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNestedGetPropertyValue() {
|
public void testNestedGetFieldValue() {
|
||||||
assertThat(ingestDocument.getPropertyValue("fizz.buzz", String.class), equalTo("hello world"));
|
assertThat(ingestDocument.getFieldValue("fizz.buzz", String.class), equalTo("hello world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetPropertyValueNotFound() {
|
public void testGetFieldValueNotFound() {
|
||||||
assertThat(ingestDocument.getPropertyValue("not.here", String.class), nullValue());
|
assertThat(ingestDocument.getFieldValue("not.here", String.class), nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetPropertyValueNull() {
|
public void testGetFieldValueNull() {
|
||||||
assertNull(ingestDocument.getPropertyValue(null, String.class));
|
assertNull(ingestDocument.getFieldValue(null, String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetPropertyValueEmpty() {
|
public void testGetFieldValueEmpty() {
|
||||||
assertNull(ingestDocument.getPropertyValue("", String.class));
|
assertNull(ingestDocument.getFieldValue("", String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasProperty() {
|
public void testHasFieldValue() {
|
||||||
assertTrue(ingestDocument.hasPropertyValue("fizz"));
|
assertTrue(ingestDocument.hasFieldValue("fizz"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPropertyValueNested() {
|
public void testHasFieldValueNested() {
|
||||||
assertTrue(ingestDocument.hasPropertyValue("fizz.buzz"));
|
assertTrue(ingestDocument.hasFieldValue("fizz.buzz"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPropertyValueNotFound() {
|
public void testHasFieldValueNotFound() {
|
||||||
assertFalse(ingestDocument.hasPropertyValue("doesnotexist"));
|
assertFalse(ingestDocument.hasFieldValue("doesnotexist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPropertyValueNestedNotFound() {
|
public void testHasFieldValueNestedNotFound() {
|
||||||
assertFalse(ingestDocument.hasPropertyValue("fizz.doesnotexist"));
|
assertFalse(ingestDocument.hasFieldValue("fizz.doesnotexist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPropertyValueNull() {
|
public void testHasFieldValueNull() {
|
||||||
assertFalse(ingestDocument.hasPropertyValue(null));
|
assertFalse(ingestDocument.hasFieldValue(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPropertyValueNullValue() {
|
public void testHasFieldValueNullValue() {
|
||||||
assertTrue(ingestDocument.hasPropertyValue("fizz.foo_null"));
|
assertTrue(ingestDocument.hasFieldValue("fizz.foo_null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPropertyValueEmpty() {
|
public void testHasFieldValueEmpty() {
|
||||||
assertFalse(ingestDocument.hasPropertyValue(""));
|
assertFalse(ingestDocument.hasFieldValue(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleSetPropertyValue() {
|
public void testSimpleSetFieldValue() {
|
||||||
ingestDocument.setPropertyValue("new_field", "foo");
|
ingestDocument.setFieldValue("new_field", "foo");
|
||||||
assertThat(ingestDocument.getSource().get("new_field"), equalTo("foo"));
|
assertThat(ingestDocument.getSource().get("new_field"), equalTo("foo"));
|
||||||
assertThat(ingestDocument.isModified(), equalTo(true));
|
assertThat(ingestDocument.isModified(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetPropertyValueNullValue() {
|
public void testSetFieldValueNullValue() {
|
||||||
ingestDocument.setPropertyValue("new_field", null);
|
ingestDocument.setFieldValue("new_field", null);
|
||||||
assertThat(ingestDocument.getSource().containsKey("new_field"), equalTo(true));
|
assertThat(ingestDocument.getSource().containsKey("new_field"), equalTo(true));
|
||||||
assertThat(ingestDocument.getSource().get("new_field"), nullValue());
|
assertThat(ingestDocument.getSource().get("new_field"), nullValue());
|
||||||
assertThat(ingestDocument.isModified(), equalTo(true));
|
assertThat(ingestDocument.isModified(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testNestedSetPropertyValue() {
|
public void testNestedSetFieldValue() {
|
||||||
ingestDocument.setPropertyValue("a.b.c.d", "foo");
|
ingestDocument.setFieldValue("a.b.c.d", "foo");
|
||||||
assertThat(ingestDocument.getSource().get("a"), instanceOf(Map.class));
|
assertThat(ingestDocument.getSource().get("a"), instanceOf(Map.class));
|
||||||
Map<String, Object> a = (Map<String, Object>) ingestDocument.getSource().get("a");
|
Map<String, Object> a = (Map<String, Object>) ingestDocument.getSource().get("a");
|
||||||
assertThat(a.get("b"), instanceOf(Map.class));
|
assertThat(a.get("b"), instanceOf(Map.class));
|
||||||
|
@ -141,14 +141,14 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
assertThat(ingestDocument.isModified(), equalTo(true));
|
assertThat(ingestDocument.isModified(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetPropertyValueOnExistingField() {
|
public void testSetFieldValueOnExistingField() {
|
||||||
ingestDocument.setPropertyValue("foo", "newbar");
|
ingestDocument.setFieldValue("foo", "newbar");
|
||||||
assertThat(ingestDocument.getSource().get("foo"), equalTo("newbar"));
|
assertThat(ingestDocument.getSource().get("foo"), equalTo("newbar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testSetPropertyValueOnExistingParent() {
|
public void testSetFieldValueOnExistingParent() {
|
||||||
ingestDocument.setPropertyValue("fizz.new", "bar");
|
ingestDocument.setFieldValue("fizz.new", "bar");
|
||||||
assertThat(ingestDocument.getSource().get("fizz"), instanceOf(Map.class));
|
assertThat(ingestDocument.getSource().get("fizz"), instanceOf(Map.class));
|
||||||
Map<String, Object> innerMap = (Map<String, Object>) ingestDocument.getSource().get("fizz");
|
Map<String, Object> innerMap = (Map<String, Object>) ingestDocument.getSource().get("fizz");
|
||||||
assertThat(innerMap.get("new"), instanceOf(String.class));
|
assertThat(innerMap.get("new"), instanceOf(String.class));
|
||||||
|
@ -157,9 +157,9 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
assertThat(ingestDocument.isModified(), equalTo(true));
|
assertThat(ingestDocument.isModified(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetPropertyValueOnExistingParentTypeMismatch() {
|
public void testSetFieldValueOnExistingParentTypeMismatch() {
|
||||||
try {
|
try {
|
||||||
ingestDocument.setPropertyValue("fizz.buzz.new", "bar");
|
ingestDocument.setFieldValue("fizz.buzz.new", "bar");
|
||||||
fail("add field should have failed");
|
fail("add field should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("cannot add field to parent [buzz] of type [java.lang.String], [java.util.Map] expected instead."));
|
assertThat(e.getMessage(), equalTo("cannot add field to parent [buzz] of type [java.lang.String], [java.util.Map] expected instead."));
|
||||||
|
@ -167,9 +167,9 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetPropertyValueOnExistingNullParent() {
|
public void testSetFieldValueOnExistingNullParent() {
|
||||||
try {
|
try {
|
||||||
ingestDocument.setPropertyValue("fizz.foo_null.test", "bar");
|
ingestDocument.setFieldValue("fizz.foo_null.test", "bar");
|
||||||
fail("add field should have failed");
|
fail("add field should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("cannot add field to null parent, [java.util.Map] expected instead."));
|
assertThat(e.getMessage(), equalTo("cannot add field to null parent, [java.util.Map] expected instead."));
|
||||||
|
@ -177,9 +177,9 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetPropertyValueNullName() {
|
public void testSetFieldValueNullName() {
|
||||||
try {
|
try {
|
||||||
ingestDocument.setPropertyValue(null, "bar");
|
ingestDocument.setFieldValue(null, "bar");
|
||||||
fail("add field should have failed");
|
fail("add field should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("cannot add null or empty field"));
|
assertThat(e.getMessage(), equalTo("cannot add null or empty field"));
|
||||||
|
@ -187,9 +187,9 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetPropertyValueEmptyName() {
|
public void testSetFieldValueEmptyName() {
|
||||||
try {
|
try {
|
||||||
ingestDocument.setPropertyValue("", "bar");
|
ingestDocument.setFieldValue("", "bar");
|
||||||
fail("add field should have failed");
|
fail("add field should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("cannot add null or empty field"));
|
assertThat(e.getMessage(), equalTo("cannot add null or empty field"));
|
||||||
|
@ -197,15 +197,15 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveProperty() {
|
public void testRemoveField() {
|
||||||
ingestDocument.removeProperty("foo");
|
ingestDocument.removeField("foo");
|
||||||
assertThat(ingestDocument.isModified(), equalTo(true));
|
assertThat(ingestDocument.isModified(), equalTo(true));
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(2));
|
assertThat(ingestDocument.getSource().size(), equalTo(2));
|
||||||
assertThat(ingestDocument.getSource().containsKey("foo"), equalTo(false));
|
assertThat(ingestDocument.getSource().containsKey("foo"), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveInnerProperty() {
|
public void testRemoveInnerField() {
|
||||||
ingestDocument.removeProperty("fizz.buzz");
|
ingestDocument.removeField("fizz.buzz");
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
||||||
assertThat(ingestDocument.getSource().get("fizz"), instanceOf(Map.class));
|
assertThat(ingestDocument.getSource().get("fizz"), instanceOf(Map.class));
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -213,33 +213,33 @@ public class IngestDocumentTests extends ESTestCase {
|
||||||
assertThat(map.size(), equalTo(1));
|
assertThat(map.size(), equalTo(1));
|
||||||
assertThat(map.containsKey("buzz"), equalTo(false));
|
assertThat(map.containsKey("buzz"), equalTo(false));
|
||||||
|
|
||||||
ingestDocument.removeProperty("fizz.foo_null");
|
ingestDocument.removeField("fizz.foo_null");
|
||||||
assertThat(map.size(), equalTo(0));
|
assertThat(map.size(), equalTo(0));
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
||||||
assertThat(ingestDocument.getSource().containsKey("fizz"), equalTo(true));
|
assertThat(ingestDocument.getSource().containsKey("fizz"), equalTo(true));
|
||||||
assertThat(ingestDocument.isModified(), equalTo(true));
|
assertThat(ingestDocument.isModified(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveNonExistingProperty() {
|
public void testRemoveNonExistingField() {
|
||||||
ingestDocument.removeProperty("does_not_exist");
|
ingestDocument.removeField("does_not_exist");
|
||||||
assertThat(ingestDocument.isModified(), equalTo(false));
|
assertThat(ingestDocument.isModified(), equalTo(false));
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveExistingParentTypeMismatch() {
|
public void testRemoveExistingParentTypeMismatch() {
|
||||||
ingestDocument.removeProperty("foo.test");
|
ingestDocument.removeField("foo.test");
|
||||||
assertThat(ingestDocument.isModified(), equalTo(false));
|
assertThat(ingestDocument.isModified(), equalTo(false));
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveNullProperty() {
|
public void testRemoveNullField() {
|
||||||
ingestDocument.removeProperty(null);
|
ingestDocument.removeField(null);
|
||||||
assertThat(ingestDocument.isModified(), equalTo(false));
|
assertThat(ingestDocument.isModified(), equalTo(false));
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveEmptyProperty() {
|
public void testRemoveEmptyField() {
|
||||||
ingestDocument.removeProperty("");
|
ingestDocument.removeField("");
|
||||||
assertThat(ingestDocument.isModified(), equalTo(false));
|
assertThat(ingestDocument.isModified(), equalTo(false));
|
||||||
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
assertThat(ingestDocument.getSource().size(), equalTo(3));
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public final class RandomDocumentPicks {
|
||||||
randomEntry = RandomPicks.randomFrom(random, treeMap.entrySet());
|
randomEntry = RandomPicks.randomFrom(random, treeMap.entrySet());
|
||||||
key += "." + randomEntry.getKey();
|
key += "." + randomEntry.getKey();
|
||||||
}
|
}
|
||||||
assert ingestDocument.getPropertyValue(key, Object.class) != null;
|
assert ingestDocument.getFieldValue(key, Object.class) != null;
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public final class RandomDocumentPicks {
|
||||||
do {
|
do {
|
||||||
fieldName = randomFieldName(random);
|
fieldName = randomFieldName(random);
|
||||||
} while (canAddField(fieldName, ingestDocument) == false);
|
} while (canAddField(fieldName, ingestDocument) == false);
|
||||||
ingestDocument.setPropertyValue(fieldName, value);
|
ingestDocument.setFieldValue(fieldName, value);
|
||||||
return fieldName;
|
return fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public abstract class AbstractStringProcessorTestCase extends ESTestCase {
|
||||||
Processor processor = newProcessor(expected.keySet());
|
Processor processor = newProcessor(expected.keySet());
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, String> entry : expected.entrySet()) {
|
for (Map.Entry<String, String> entry : expected.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public abstract class AbstractStringProcessorTestCase extends ESTestCase {
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
Processor processor = newProcessor(Collections.singletonList(fieldName));
|
Processor processor = newProcessor(Collections.singletonList(fieldName));
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
ingestDocument.setPropertyValue(fieldName, randomInt());
|
ingestDocument.setFieldValue(fieldName, randomInt());
|
||||||
try {
|
try {
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
fail("processor should have failed");
|
fail("processor should have failed");
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class AddProcessorTests extends ESTestCase {
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
|
|
||||||
for (Map.Entry<String, Object> field : fields.entrySet()) {
|
for (Map.Entry<String, Object> field : fields.entrySet()) {
|
||||||
assertThat(ingestDocument.hasPropertyValue(field.getKey()), equalTo(true));
|
assertThat(ingestDocument.hasFieldValue(field.getKey()), equalTo(true));
|
||||||
assertThat(ingestDocument.getPropertyValue(field.getKey(), Object.class), equalTo(field.getValue()));
|
assertThat(ingestDocument.getFieldValue(field.getKey(), Object.class), equalTo(field.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,14 +63,14 @@ public class AddProcessorTests extends ESTestCase {
|
||||||
Processor processor = new AddProcessor(fields);
|
Processor processor = new AddProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, Object> field : fields.entrySet()) {
|
for (Map.Entry<String, Object> field : fields.entrySet()) {
|
||||||
assertThat(ingestDocument.hasPropertyValue(field.getKey()), equalTo(true));
|
assertThat(ingestDocument.hasFieldValue(field.getKey()), equalTo(true));
|
||||||
assertThat(ingestDocument.getPropertyValue(field.getKey(), Object.class), equalTo(field.getValue()));
|
assertThat(ingestDocument.getFieldValue(field.getKey(), Object.class), equalTo(field.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddFieldsTypeMismatch() throws IOException {
|
public void testAddFieldsTypeMismatch() throws IOException {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
ingestDocument.setPropertyValue("field", "value");
|
ingestDocument.setFieldValue("field", "value");
|
||||||
Processor processor = new AddProcessor(Collections.singletonMap("field.inner", "value"));
|
Processor processor = new AddProcessor(Collections.singletonMap("field.inner", "value"));
|
||||||
try {
|
try {
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, Integer> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, Integer> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), Integer.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), Integer.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, List<Integer>> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, List<Integer>> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
String value = "string-" + randomAsciiOfLengthBetween(1, 10);
|
String value = "string-" + randomAsciiOfLengthBetween(1, 10);
|
||||||
ingestDocument.setPropertyValue(fieldName, value);
|
ingestDocument.setFieldValue(fieldName, value);
|
||||||
|
|
||||||
Map<String, Type> convert = Collections.singletonMap(fieldName, Type.INTEGER);
|
Map<String, Type> convert = Collections.singletonMap(fieldName, Type.INTEGER);
|
||||||
Processor processor = new ConvertProcessor(convert);
|
Processor processor = new ConvertProcessor(convert);
|
||||||
|
@ -106,7 +106,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, Float> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, Float> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), Float.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), Float.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, List<Float>> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, List<Float>> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
String value = "string-" + randomAsciiOfLengthBetween(1, 10);
|
String value = "string-" + randomAsciiOfLengthBetween(1, 10);
|
||||||
ingestDocument.setPropertyValue(fieldName, value);
|
ingestDocument.setFieldValue(fieldName, value);
|
||||||
|
|
||||||
Map<String, Type> convert = Collections.singletonMap(fieldName, Type.FLOAT);
|
Map<String, Type> convert = Collections.singletonMap(fieldName, Type.FLOAT);
|
||||||
Processor processor = new ConvertProcessor(convert);
|
Processor processor = new ConvertProcessor(convert);
|
||||||
|
@ -170,7 +170,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, Boolean> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, Boolean> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), Boolean.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), Boolean.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, List<Boolean>> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, List<Boolean>> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
//verify that only proper boolean values are supported and we are strict about it
|
//verify that only proper boolean values are supported and we are strict about it
|
||||||
fieldValue = randomFrom("on", "off", "yes", "no", "0", "1");
|
fieldValue = randomFrom("on", "off", "yes", "no", "0", "1");
|
||||||
}
|
}
|
||||||
ingestDocument.setPropertyValue(fieldName, fieldValue);
|
ingestDocument.setFieldValue(fieldName, fieldValue);
|
||||||
|
|
||||||
Map<String, Type> convert = Collections.singletonMap(fieldName, Type.BOOLEAN);
|
Map<String, Type> convert = Collections.singletonMap(fieldName, Type.BOOLEAN);
|
||||||
Processor processor = new ConvertProcessor(convert);
|
Processor processor = new ConvertProcessor(convert);
|
||||||
|
@ -260,7 +260,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, String> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, String> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
||||||
Processor processor = new ConvertProcessor(fields);
|
Processor processor = new ConvertProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, List<String>> entry : expectedResult.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : expectedResult.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), List.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", "2010 12 06 11:05:15");
|
document.put("date_as_string", "2010 12 06 11:05:15");
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("2010-06-12T11:05:15.000+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T11:05:15.000+02:00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testJodaPatternMultipleFormats() {
|
public void testJodaPatternMultipleFormats() {
|
||||||
|
@ -53,19 +53,19 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", "2010 12 06");
|
document.put("date_as_string", "2010 12 06");
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||||
|
|
||||||
document = new HashMap<>();
|
document = new HashMap<>();
|
||||||
document.put("date_as_string", "12/06/2010");
|
document.put("date_as_string", "12/06/2010");
|
||||||
ingestDocument = new IngestDocument("index", "type", "id", document);
|
ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||||
|
|
||||||
document = new HashMap<>();
|
document = new HashMap<>();
|
||||||
document.put("date_as_string", "12-06-2010");
|
document.put("date_as_string", "12-06-2010");
|
||||||
ingestDocument = new IngestDocument("index", "type", "id", document);
|
ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||||
|
|
||||||
document = new HashMap<>();
|
document = new HashMap<>();
|
||||||
document.put("date_as_string", "2010");
|
document.put("date_as_string", "2010");
|
||||||
|
@ -85,7 +85,7 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", "2010 12 giugno");
|
document.put("date_as_string", "2010 12 giugno");
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testJodaPatternDefaultYear() {
|
public void testJodaPatternDefaultYear() {
|
||||||
|
@ -95,7 +95,7 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", "12/06");
|
document.put("date_as_string", "12/06");
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo(DateTime.now().getYear() + "-06-12T00:00:00.000+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo(DateTime.now().getYear() + "-06-12T00:00:00.000+02:00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTAI64N() {
|
public void testTAI64N() {
|
||||||
|
@ -106,7 +106,7 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", dateAsString);
|
document.put("date_as_string", dateAsString);
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("2012-12-22T03:00:46.767+02:00"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2012-12-22T03:00:46.767+02:00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnixMs() {
|
public void testUnixMs() {
|
||||||
|
@ -116,7 +116,7 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", "1000500");
|
document.put("date_as_string", "1000500");
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnix() {
|
public void testUnix() {
|
||||||
|
@ -126,6 +126,6 @@ public class DateProcessorTests extends ESTestCase {
|
||||||
document.put("date_as_string", "1000.5");
|
document.put("date_as_string", "1000.5");
|
||||||
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", document);
|
||||||
dateProcessor.execute(ingestDocument);
|
dateProcessor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.getPropertyValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
|
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,14 +46,14 @@ public class GsubProcessorTests extends ESTestCase {
|
||||||
Processor processor = new GsubProcessor(expressions);
|
Processor processor = new GsubProcessor(expressions);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (GsubExpression expression : expressions) {
|
for (GsubExpression expression : expressions) {
|
||||||
assertThat(ingestDocument.getPropertyValue(expression.getFieldName(), String.class), equalTo("127-0-0-1"));
|
assertThat(ingestDocument.getFieldValue(expression.getFieldName(), String.class), equalTo("127-0-0-1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGsubNotAStringValue() throws IOException {
|
public void testGsubNotAStringValue() throws IOException {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
ingestDocument.setPropertyValue(fieldName, 123);
|
ingestDocument.setFieldValue(fieldName, 123);
|
||||||
List<GsubExpression> gsubExpressions = Collections.singletonList(new GsubExpression(fieldName, Pattern.compile("\\."), "-"));
|
List<GsubExpression> gsubExpressions = Collections.singletonList(new GsubExpression(fieldName, Pattern.compile("\\."), "-"));
|
||||||
Processor processor = new GsubProcessor(gsubExpressions);
|
Processor processor = new GsubProcessor(gsubExpressions);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class JoinProcessorTests extends ESTestCase {
|
||||||
Processor processor = new JoinProcessor(fields);
|
Processor processor = new JoinProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, String> entry : expectedResultMap.entrySet()) {
|
for (Map.Entry<String, String> entry : expectedResultMap.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,14 +87,14 @@ public class JoinProcessorTests extends ESTestCase {
|
||||||
Processor processor = new JoinProcessor(fields);
|
Processor processor = new JoinProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, String> entry : expectedResultMap.entrySet()) {
|
for (Map.Entry<String, String> entry : expectedResultMap.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), String.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testJoinNonListField() throws IOException {
|
public void testJoinNonListField() throws IOException {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
ingestDocument.setPropertyValue(fieldName, randomAsciiOfLengthBetween(1, 10));
|
ingestDocument.setFieldValue(fieldName, randomAsciiOfLengthBetween(1, 10));
|
||||||
Map<String, String> join = Collections.singletonMap(fieldName, "-");
|
Map<String, String> join = Collections.singletonMap(fieldName, "-");
|
||||||
Processor processor = new JoinProcessor(join);
|
Processor processor = new JoinProcessor(join);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -45,8 +45,8 @@ public class RemoveProcessorTests extends ESTestCase {
|
||||||
Processor processor = new RemoveProcessor(fields);
|
Processor processor = new RemoveProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (String field : fields) {
|
for (String field : fields) {
|
||||||
assertThat(ingestDocument.getPropertyValue(field, Object.class), nullValue());
|
assertThat(ingestDocument.getFieldValue(field, Object.class), nullValue());
|
||||||
assertThat(ingestDocument.hasPropertyValue(field), equalTo(false));
|
assertThat(ingestDocument.hasFieldValue(field), equalTo(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,13 @@ public class RenameProcessorTests extends ESTestCase {
|
||||||
do {
|
do {
|
||||||
newFieldName = RandomDocumentPicks.randomFieldName(random());
|
newFieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
} while (RandomDocumentPicks.canAddField(newFieldName, ingestDocument) == false || newFields.containsKey(newFieldName));
|
} while (RandomDocumentPicks.canAddField(newFieldName, ingestDocument) == false || newFields.containsKey(newFieldName));
|
||||||
newFields.put(newFieldName, ingestDocument.getPropertyValue(fieldName, Object.class));
|
newFields.put(newFieldName, ingestDocument.getFieldValue(fieldName, Object.class));
|
||||||
fields.put(fieldName, newFieldName);
|
fields.put(fieldName, newFieldName);
|
||||||
}
|
}
|
||||||
Processor processor = new RenameProcessor(fields);
|
Processor processor = new RenameProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (Map.Entry<String, Object> entry : newFields.entrySet()) {
|
for (Map.Entry<String, Object> entry : newFields.entrySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(entry.getKey(), Object.class), equalTo(entry.getValue()));
|
assertThat(ingestDocument.getFieldValue(entry.getKey(), Object.class), equalTo(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,12 +66,12 @@ public class RenameProcessorTests extends ESTestCase {
|
||||||
public void testRenameExistingFieldNullValue() throws IOException {
|
public void testRenameExistingFieldNullValue() throws IOException {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
ingestDocument.setPropertyValue(fieldName, null);
|
ingestDocument.setFieldValue(fieldName, null);
|
||||||
String newFieldName = RandomDocumentPicks.randomFieldName(random());
|
String newFieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
Processor processor = new RenameProcessor(Collections.singletonMap(fieldName, newFieldName));
|
Processor processor = new RenameProcessor(Collections.singletonMap(fieldName, newFieldName));
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
assertThat(ingestDocument.hasPropertyValue(fieldName), equalTo(false));
|
assertThat(ingestDocument.hasFieldValue(fieldName), equalTo(false));
|
||||||
assertThat(ingestDocument.hasPropertyValue(newFieldName), equalTo(true));
|
assertThat(ingestDocument.hasFieldValue(newFieldName), equalTo(true));
|
||||||
assertThat(ingestDocument.getPropertyValue(newFieldName, Object.class), nullValue());
|
assertThat(ingestDocument.getFieldValue(newFieldName, Object.class), nullValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class SplitProcessorTests extends ESTestCase {
|
||||||
Processor processor = new SplitProcessor(fields);
|
Processor processor = new SplitProcessor(fields);
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
for (String field : fields.keySet()) {
|
for (String field : fields.keySet()) {
|
||||||
assertThat(ingestDocument.getPropertyValue(field, List.class), equalTo(Arrays.asList("127", "0", "0", "1")));
|
assertThat(ingestDocument.getFieldValue(field, List.class), equalTo(Arrays.asList("127", "0", "0", "1")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class SplitProcessorTests extends ESTestCase {
|
||||||
public void testSplitNonStringValue() throws IOException {
|
public void testSplitNonStringValue() throws IOException {
|
||||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
||||||
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
||||||
ingestDocument.setPropertyValue(fieldName, randomInt());
|
ingestDocument.setFieldValue(fieldName, randomInt());
|
||||||
Processor processor = new SplitProcessor(Collections.singletonMap(fieldName, "\\."));
|
Processor processor = new SplitProcessor(Collections.singletonMap(fieldName, "\\."));
|
||||||
try {
|
try {
|
||||||
processor.execute(ingestDocument);
|
processor.execute(ingestDocument);
|
||||||
|
|
|
@ -174,7 +174,7 @@ public class IngestActionFilterTests extends ESTestCase {
|
||||||
Processor processor = new Processor() {
|
Processor processor = new Processor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(IngestDocument ingestDocument) {
|
public void execute(IngestDocument ingestDocument) {
|
||||||
ingestDocument.setPropertyValue("field2", "value2");
|
ingestDocument.setFieldValue("field2", "value2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue