Search in sources :

Example 36 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class JsonProcessorTests method testDouble.

public void testDouble() throws Exception {
    JsonProcessor jsonProcessor = new JsonProcessor("tag", null, "field", "target_field", false);
    Map<String, Object> document = new HashMap<>();
    double value = 3.0;
    document.put("field", value);
    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)

Example 37 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class KeyValueProcessorTests method test.

public void test() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello&second=world&second=universe");
    Processor processor = createKvProcessor(fieldName, "&", "=", null, null, "target", false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
    assertThat(ingestDocument.getFieldValue("target.second", List.class), equalTo(Arrays.asList("world", "universe")));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List)

Example 38 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class KeyValueProcessorTests method testTrimKeyAndValue.

public void testTrimKeyAndValue() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first= hello &second=world& second =universe");
    Processor processor = createKvProcessor(fieldName, "&", "=", null, null, "target", false, " ", " ", false, null);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
    assertThat(ingestDocument.getFieldValue("target.second", List.class), equalTo(Arrays.asList("world", "universe")));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class KeyValueProcessorTests method testRootTarget.

public void testRootTarget() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    ingestDocument.setFieldValue("myField", "first=hello&second=world&second=universe");
    Processor processor = createKvProcessor("myField", "&", "=", null, null, null, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("first", String.class), equalTo("hello"));
    assertThat(ingestDocument.getFieldValue("second", List.class), equalTo(Arrays.asList("world", "universe")));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with IngestDocument

use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.

the class KeyValueProcessorTests method testKeySameAsSourceField.

public void testKeySameAsSourceField() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    ingestDocument.setFieldValue("first", "first=hello");
    Processor processor = createKvProcessor("first", "&", "=", null, null, null, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("first", List.class), equalTo(Arrays.asList("first=hello", "hello")));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) ArrayList(java.util.ArrayList) List(java.util.List)

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