use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class GrokProcessorTests method testCombineSamePatternNameAcrossPatterns.
public void testCombineSamePatternNameAcrossPatterns() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
IngestDocument doc = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
doc.setFieldValue(fieldName, "1-3");
Map<String, String> patternBank = new HashMap<>();
patternBank.put("ONE", "1");
patternBank.put("TWO", "2");
patternBank.put("THREE", "3");
GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, patternBank, Arrays.asList("%{ONE:first}-%{TWO:second}", "%{ONE:first}-%{THREE:second}"), fieldName, randomBoolean(), randomBoolean(), MatcherWatchdog.noop());
processor.execute(doc);
assertThat(doc.getFieldValue("first", String.class), equalTo("1"));
assertThat(doc.getFieldValue("second", String.class), equalTo("3"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class GrokProcessorTests method testNullFieldWithIgnoreMissing.
public void testNullFieldWithIgnoreMissing() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
originalIngestDocument.setFieldValue(fieldName, null);
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, true, MatcherWatchdog.noop());
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class GrokProcessorTests method testMissingFieldWithIgnoreMissing.
public void testMissingFieldWithIgnoreMissing() throws Exception {
String fieldName = "foo.bar";
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
GrokProcessor processor = new GrokProcessor(randomAlphaOfLength(10), null, Collections.singletonMap("ONE", "1"), Collections.singletonList("%{ONE:one}"), fieldName, false, true, MatcherWatchdog.noop());
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JoinProcessorTests method testJoinIntegers.
public void testJoinIntegers() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int numItems = randomIntBetween(1, 10);
String separator = randomFrom(SEPARATORS);
List<Integer> fieldValue = new ArrayList<>(numItems);
String expectedResult = "";
for (int j = 0; j < numItems; j++) {
int value = randomInt();
fieldValue.add(value);
expectedResult += value;
if (j < numItems - 1) {
expectedResult += separator;
}
}
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
Processor processor = new JoinProcessor(randomAlphaOfLength(10), null, fieldName, separator, fieldName);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class JoinProcessorTests method testJoinStrings.
public void testJoinStrings() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int numItems = randomIntBetween(1, 10);
String separator = randomFrom(SEPARATORS);
List<String> fieldValue = new ArrayList<>(numItems);
String expectedResult = "";
for (int j = 0; j < numItems; j++) {
String value = randomAlphaOfLengthBetween(1, 10);
fieldValue.add(value);
expectedResult += value;
if (j < numItems - 1) {
expectedResult += separator;
}
}
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
Processor processor = new JoinProcessor(randomAlphaOfLength(10), null, fieldName, separator, fieldName);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedResult));
}
Aggregations