/** * Adds a random non existing field to the provided document and associates it with the provided * value. The field will be added at a random position within the document, not necessarily at the * top level using a leaf field name. */ public static String addRandomField(Random random, IngestDocument ingestDocument, Object value) { String fieldName; do { fieldName = randomFieldName(random); } while (canAddField(fieldName, ingestDocument) == false); ingestDocument.setFieldValue(fieldName, value); return fieldName; }
@Override public void execute(IngestDocument ingestDocument) throws Exception { String fieldValue = ingestDocument.getFieldValue(matchField, String.class); Map<String, Object> matches = grok.captures(fieldValue); if (matches != null) { matches.forEach((k, v) -> ingestDocument.setFieldValue(k, v)); } else { throw new IllegalArgumentException( "Grok expression does not match field value: [" + fieldValue + "]"); } }