use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class CsvProcessorTests method testQuotedWhitespaces.
public void testQuotedWhitespaces() {
assumeFalse("quote needed", quote.isEmpty());
IngestDocument document = processDocument(new String[] { "a", "b", "c", "d" }, " abc " + separator + " def" + separator + "ghi " + separator + " " + quote + " ooo " + quote);
assertEquals("abc", document.getFieldValue("a", String.class));
assertEquals("def", document.getFieldValue("b", String.class));
assertEquals("ghi", document.getFieldValue("c", String.class));
assertEquals(" ooo ", document.getFieldValue("d", String.class));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JsonProcessorTests method testInvalidValue.
public void testInvalidValue() {
JsonProcessor jsonProcessor = new JsonProcessor("tag", null, "field", "target_field", false);
Map<String, Object> document = new HashMap<>();
document.put("field", "blah blah");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
Exception exception = expectThrows(IllegalArgumentException.class, () -> jsonProcessor.execute(ingestDocument));
assertThat(exception.getCause().getMessage(), containsString("Unrecognized token 'blah': " + "was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JsonProcessorTests method testAddToRoot.
public void testAddToRoot() throws Exception {
String processorTag = randomAlphaOfLength(3);
String randomTargetField = randomAlphaOfLength(2);
JsonProcessor jsonProcessor = new JsonProcessor(processorTag, null, "a", randomTargetField, true);
Map<String, Object> document = new HashMap<>();
String json = "{\"a\": 1, \"b\": 2}";
document.put("a", json);
document.put("c", "see");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
jsonProcessor.execute(ingestDocument);
Map<String, Object> sourceAndMetadata = ingestDocument.getSourceAndMetadata();
assertEquals(1, sourceAndMetadata.get("a"));
assertEquals(2, sourceAndMetadata.get("b"));
assertEquals("see", sourceAndMetadata.get("c"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JsonProcessorTests method testNull.
public void testNull() throws Exception {
JsonProcessor jsonProcessor = new JsonProcessor("tag", null, "field", "target_field", false);
Map<String, Object> document = new HashMap<>();
document.put("field", null);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
jsonProcessor.execute(ingestDocument);
assertNull(ingestDocument.getFieldValue("target_field", Object.class));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JsonProcessorTests method testArray.
public void testArray() throws Exception {
JsonProcessor jsonProcessor = new JsonProcessor("tag", null, "field", "target_field", false);
Map<String, Object> document = new HashMap<>();
List<Boolean> value = Arrays.asList(true, true, false);
document.put("field", value.toString());
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
jsonProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("target_field", Object.class), equalTo(value));
}
Aggregations