use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class ConvertProcessorTests method testConvertDoubleList.
public void testConvertDoubleList() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int numItems = randomIntBetween(1, 10);
List<String> fieldValue = new ArrayList<>();
List<Double> expectedList = new ArrayList<>();
for (int j = 0; j < numItems; j++) {
double randomDouble = randomDouble();
fieldValue.add(Double.toString(randomDouble));
expectedList.add(randomDouble);
}
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), null, fieldName, fieldName, Type.DOUBLE, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class AbstractStringProcessorTestCase method testNonStringValueWithIgnoreMissing.
public void testNonStringValueWithIgnoreMissing() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
Processor processor = newProcessor(fieldName, true, fieldName);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
ingestDocument.setFieldValue(fieldName, randomInt());
Exception e = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
assertThat(e.getMessage(), equalTo("field [" + fieldName + "] of type [java.lang.Integer] cannot be cast to [java.lang.String]"));
List<Integer> fieldValueList = new ArrayList<>();
int randomValue = randomInt();
fieldValueList.add(randomValue);
ingestDocument.setFieldValue(fieldName, fieldValueList);
Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
assertThat(exception.getMessage(), equalTo("value [" + randomValue + "] of type [java.lang.Integer] in list field [" + fieldName + "] cannot be cast to [java.lang.String]"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class AbstractStringProcessorTestCase method testTargetField.
public void testTargetField() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
String fieldValue = RandomDocumentPicks.randomString(random());
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, modifyInput(fieldValue));
String targetFieldName = fieldName + "foo";
Processor processor = newProcessor(fieldName, randomBoolean(), targetFieldName);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(targetFieldName, expectedResultType()), equalTo(expectedResult(fieldValue)));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class AbstractStringProcessorTestCase method testFieldNotFoundWithIgnoreMissing.
public void testFieldNotFoundWithIgnoreMissing() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
Processor processor = newProcessor(fieldName, true, fieldName);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class AbstractStringProcessorTestCase method testNullValue.
public void testNullValue() throws Exception {
Processor processor = newProcessor("field", false, "field");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
Exception e = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
assertThat(e.getMessage(), equalTo("field [field] is null, cannot process it."));
}
Aggregations