Search in sources :

Example 31 with IngestDocument

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));
}
Also used : IngestDocument(org.opensearch.ingest.IngestDocument)

Example 32 with IngestDocument

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')"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 33 with IngestDocument

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"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 34 with IngestDocument

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));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 35 with IngestDocument

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));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

IngestDocument (org.opensearch.ingest.IngestDocument)252 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)150 Processor (org.opensearch.ingest.Processor)136 Matchers.containsString (org.hamcrest.Matchers.containsString)98 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)51 Map (java.util.Map)37 List (java.util.List)36 GeoIpCache (org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)19 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)13 TestProcessor (org.opensearch.ingest.TestProcessor)12 SortOrder (org.opensearch.ingest.common.SortProcessor.SortOrder)12 Arrays (java.util.Arrays)11 Collectors (java.util.stream.Collectors)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 LinkedHashMap (java.util.LinkedHashMap)9 RandomDocumentPicks (org.opensearch.ingest.RandomDocumentPicks)9 Name (com.carrotsearch.randomizedtesting.annotations.Name)7 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)7 LinkedList (java.util.LinkedList)7