2727
2828import java .util .Collections ;
2929import java .util .HashMap ;
30+ import java .util .Map ;
3031
3132import static org .hamcrest .Matchers .containsString ;
3233import static org .hamcrest .Matchers .equalTo ;
@@ -37,21 +38,34 @@ public void testRemoveFields() throws Exception {
3738 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
3839 String field = RandomDocumentPicks .randomExistingFieldName (random (), ingestDocument );
3940 Processor processor = new RemoveProcessor (randomAlphaOfLength (10 ),
40- Collections .singletonList (new TestTemplateService .MockTemplateScript .Factory (field )));
41+ Collections .singletonList (new TestTemplateService .MockTemplateScript .Factory (field )), false );
4142 processor .execute (ingestDocument );
4243 assertThat (ingestDocument .hasField (field ), equalTo (false ));
4344 }
4445
4546 public void testRemoveNonExistingField () throws Exception {
4647 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
4748 String fieldName = RandomDocumentPicks .randomFieldName (random ());
48- Processor processor = new RemoveProcessor (randomAlphaOfLength (10 ),
49- Collections .singletonList (new TestTemplateService .MockTemplateScript .Factory (fieldName )));
49+ Map <String , Object > config = new HashMap <>();
50+ config .put ("field" , fieldName );
51+ String processorTag = randomAlphaOfLength (10 );
52+ Processor processor = new RemoveProcessor .Factory (TestTemplateService .instance ()).create (null , processorTag , config );
5053 try {
5154 processor .execute (ingestDocument );
5255 fail ("remove field should have failed" );
5356 } catch (IllegalArgumentException e ) {
5457 assertThat (e .getMessage (), containsString ("not present as part of path [" + fieldName + "]" ));
5558 }
5659 }
60+
61+ public void testIgnoreMissing () throws Exception {
62+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
63+ String fieldName = RandomDocumentPicks .randomFieldName (random ());
64+ Map <String , Object > config = new HashMap <>();
65+ config .put ("field" , fieldName );
66+ config .put ("ignore_missing" , true );
67+ String processorTag = randomAlphaOfLength (10 );
68+ Processor processor = new RemoveProcessor .Factory (TestTemplateService .instance ()).create (null , processorTag , config );
69+ processor .execute (ingestDocument );
70+ }
5771}
0 commit comments