use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class UserAgentProcessorTests method testSpider.
@SuppressWarnings("unchecked")
public void testSpider() throws Exception {
Map<String, Object> document = new HashMap<>();
document.put("source_field", "Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
processor.execute(ingestDocument);
Map<String, Object> data = ingestDocument.getSourceAndMetadata();
assertThat(data, hasKey("target_field"));
Map<String, Object> target = (Map<String, Object>) data.get("target_field");
assertThat(target.get("name"), is("EasouSpider"));
assertNull(target.get("version"));
assertNull(target.get("os"));
Map<String, String> device = new HashMap<>();
device.put("name", "Spider");
assertThat(target.get("device"), is(device));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class UserAgentProcessorTests method testNullValueWithIgnoreMissing.
public void testNullValueWithIgnoreMissing() throws Exception {
UserAgentProcessor processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), true, true);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("source_field", null));
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class RemoveProcessorTests method testIgnoreMissing.
public void testIgnoreMissing() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
String fieldName = RandomDocumentPicks.randomFieldName(random());
Map<String, Object> config = new HashMap<>();
config.put("field", fieldName);
config.put("ignore_missing", true);
String processorTag = randomAlphaOfLength(10);
Processor processor = new RemoveProcessor.Factory(TestTemplateService.instance()).create(null, processorTag, null, config);
processor.execute(ingestDocument);
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class RenameProcessorTests method testRenameAtomicOperationRemoveFails.
public void testRenameAtomicOperationRemoveFails() throws Exception {
Map<String, Object> source = new HashMap<String, Object>() {
@Override
public Object remove(Object key) {
if (key.equals("list")) {
throw new UnsupportedOperationException();
}
return super.remove(key);
}
};
source.put("list", Collections.singletonList("item"));
IngestDocument ingestDocument = new IngestDocument(source, Collections.emptyMap());
Processor processor = createRenameProcessor("list", "new_field", false);
try {
processor.execute(ingestDocument);
fail("processor execute should have failed");
} catch (UnsupportedOperationException e) {
// the set failed, the old field has not been removed
assertThat(ingestDocument.getSourceAndMetadata().containsKey("list"), equalTo(true));
assertThat(ingestDocument.getSourceAndMetadata().containsKey("new_field"), equalTo(false));
}
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class RenameProcessorTests method testRenameArrayElement.
public void testRenameArrayElement() throws Exception {
Map<String, Object> document = new HashMap<>();
List<String> list = new ArrayList<>();
list.add("item1");
list.add("item2");
list.add("item3");
document.put("list", list);
List<Map<String, String>> one = new ArrayList<>();
one.add(Collections.singletonMap("one", "one"));
one.add(Collections.singletonMap("two", "two"));
document.put("one", one);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
Processor processor = createRenameProcessor("list.0", "item", false);
processor.execute(ingestDocument);
Object actualObject = ingestDocument.getSourceAndMetadata().get("list");
assertThat(actualObject, instanceOf(List.class));
@SuppressWarnings("unchecked") List<String> actualList = (List<String>) actualObject;
assertThat(actualList.size(), equalTo(2));
assertThat(actualList.get(0), equalTo("item2"));
assertThat(actualList.get(1), equalTo("item3"));
actualObject = ingestDocument.getSourceAndMetadata().get("item");
assertThat(actualObject, instanceOf(String.class));
assertThat(actualObject, equalTo("item1"));
processor = createRenameProcessor("list.0", "list.3", false);
try {
processor.execute(ingestDocument);
fail("processor execute should have failed");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("[3] is out of bounds for array with length [2] as part of path [list.3]"));
assertThat(actualList.size(), equalTo(2));
assertThat(actualList.get(0), equalTo("item2"));
assertThat(actualList.get(1), equalTo("item3"));
}
}
Aggregations