Search in sources :

Example 96 with IngestDocument

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

the class SetProcessorTests method testSetFieldsTypeMismatch.

public void testSetFieldsTypeMismatch() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
    ingestDocument.setFieldValue("field", "value");
    Processor processor = createSetProcessor("field.inner", "value", true, false);
    try {
        processor.execute(ingestDocument);
        fail("processor execute should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("cannot set [inner] with parent object of type [java.lang.String] as " + "part of path [field.inner]"));
    }
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 97 with IngestDocument

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

the class SetProcessorTests method testSetMetadataExceptVersion.

public void testSetMetadataExceptVersion() throws Exception {
    Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING);
    Processor processor = createSetProcessor(randomMetadata.getFieldName(), "_value", true, false);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(randomMetadata.getFieldName(), String.class), Matchers.equalTo("_value"));
}
Also used : Processor(org.opensearch.ingest.Processor) Metadata(org.opensearch.ingest.IngestDocument.Metadata) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 98 with IngestDocument

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

the class SetProcessorTests method testSetExistingFieldWithOverrideDisabled.

public void testSetExistingFieldWithOverrideDisabled() throws Exception {
    IngestDocument ingestDocument = new IngestDocument(new HashMap<>(), new HashMap<>());
    Object fieldValue = "foo";
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
    Processor processor = createSetProcessor(fieldName, "bar", false, false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.hasField(fieldName), equalTo(true));
    assertThat(ingestDocument.getFieldValue(fieldName, Object.class), equalTo(fieldValue));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 99 with IngestDocument

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

the class SetProcessorTests method testSetMetadataIfSeqNo.

public void testSetMetadataIfSeqNo() throws Exception {
    long ifSeqNo = randomNonNegativeLong();
    Processor processor = createSetProcessor(Metadata.IF_SEQ_NO.getFieldName(), ifSeqNo, true, false);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue(Metadata.IF_SEQ_NO.getFieldName(), Long.class), Matchers.equalTo(ifSeqNo));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 100 with IngestDocument

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

the class ForEachProcessorTests method testRemovingFromTheSameField.

public void testRemovingFromTheSameField() {
    Map<String, Object> source = Collections.singletonMap("field", Arrays.asList("a", "b"));
    IngestDocument originalIngestDocument = new IngestDocument("_index", "_id", null, null, null, source);
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    TestProcessor testProcessor = new TestProcessor(id -> id.removeField("field.0"));
    ForEachProcessor processor = new ForEachProcessor("_tag", null, "field", testProcessor, true);
    processor.execute(ingestDocument, (result, e) -> {
    });
    assertThat(testProcessor.getInvokedCounter(), equalTo(2));
    ingestDocument.removeField("_ingest._value");
    assertThat(ingestDocument, equalTo(originalIngestDocument));
}
Also used : IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) TestProcessor(org.opensearch.ingest.TestProcessor)

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