use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JoinProcessorTests method testJoinNullValue.
public void testJoinNullValue() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
Processor processor = new JoinProcessor(randomAlphaOfLength(10), null, "field", "-", "field");
try {
processor.execute(ingestDocument);
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("field [field] is null, cannot join."));
}
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class ConvertProcessorTests method testConvertInt.
public void testConvertInt() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int randomInt = randomInt();
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomInt);
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, Type.INTEGER, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, Integer.class), equalTo(randomInt));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class ConvertProcessorTests method testConvertNullField.
public void testConvertNullField() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
Type type = randomFrom(Type.values());
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, "field", "field", type, false);
try {
processor.execute(ingestDocument);
fail("processor execute should have failed");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("Field [field] is null, cannot be converted to type [" + type + "]"));
}
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class ConvertProcessorTests method testAutoConvertMatchFloat.
public void testAutoConvertMatchFloat() throws Exception {
float randomFloat = randomFloat();
String randomString = Float.toString(randomFloat);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", randomString));
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, "field", "field", Type.AUTO, false);
processor.execute(ingestDocument);
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
assertThat(convertedValue, equalTo(randomFloat));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class ConvertProcessorTests method testConvertDoubleError.
public void testConvertDoubleError() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
String fieldName = RandomDocumentPicks.randomFieldName(random());
String value = "string-" + randomAlphaOfLengthBetween(1, 10);
ingestDocument.setFieldValue(fieldName, value);
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, Type.DOUBLE, false);
try {
processor.execute(ingestDocument);
fail("processor execute should have failed");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("unable to convert [" + value + "] to double"));
}
}
Aggregations