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]"));
}
}
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"));
}
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));
}
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));
}
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));
}
Aggregations