8
8
import java .nio .file .Path ;
9
9
10
10
import org .junit .Before ;
11
+ import org .opensearch .client .ResponseException ;
11
12
import org .opensearch .neuralsearch .BaseNeuralSearchIT ;
12
13
13
14
/**
@@ -21,19 +22,15 @@ public class TextImageEmbeddingProcessorIT extends BaseNeuralSearchIT {
21
22
private static final String INGEST_DOCUMENT = "{\n "
22
23
+ " \" title\" : \" This is a good day\" ,\n "
23
24
+ " \" description\" : \" daily logging\" ,\n "
24
- + " \" passage_text\" : \" A very nice day today\" ,\n "
25
+ + " \" passage_text\" : \" passage_text_value\" ,\n "
26
+ + " \" text\" : \" \" ,\n "
27
+ + " \" image\" : null,\n "
25
28
+ " \" favorites\" : {\n "
26
29
+ " \" game\" : \" overwatch\" ,\n "
27
30
+ " \" movie\" : null\n "
28
31
+ " }\n "
29
32
+ "}\n " ;
30
33
31
- private static final String INGEST_DOCUMENT_UNMAPPED_FIELDS = "{\n "
32
- + " \" title\" : \" This is a good day\" ,\n "
33
- + " \" description\" : \" daily logging\" ,\n "
34
- + " \" some_random_field\" : \" Today is a sunny weather\" \n "
35
- + "}\n " ;
36
-
37
34
@ Before
38
35
public void setUp () throws Exception {
39
36
super .setUp ();
@@ -51,13 +48,24 @@ public void testEmbeddingProcessor_whenIngestingDocumentWithOrWithoutSourceMatch
51
48
ingestDocument (INDEX_NAME , INGEST_DOCUMENT );
52
49
assertEquals (1 , getDocCount (INDEX_NAME ));
53
50
// verify doc without mapping
54
- ingestDocument (INDEX_NAME , INGEST_DOCUMENT_UNMAPPED_FIELDS );
51
+ String documentWithUnmappedFields ;
52
+ documentWithUnmappedFields = INGEST_DOCUMENT .replace ("passage_text" , "random_field_1" );
53
+ ingestDocument (INDEX_NAME , documentWithUnmappedFields );
55
54
assertEquals (2 , getDocCount (INDEX_NAME ));
56
55
} finally {
57
56
wipeOfTestResources (INDEX_NAME , PIPELINE_NAME , modelId , null );
58
57
}
59
58
}
60
59
60
+ public void testEmbeddingProcessor_whenIngestingDocumentWithNullMappingValue_thenThrowException () throws Exception {
61
+ String modelId = uploadModel ();
62
+ loadModel (modelId );
63
+ createPipelineProcessor (modelId , PIPELINE_NAME , ProcessorType .TEXT_IMAGE_EMBEDDING );
64
+ createIndexWithPipeline (INDEX_NAME , "IndexMappings.json" , PIPELINE_NAME );
65
+
66
+ expectThrows (ResponseException .class , () -> ingestDocument (INDEX_NAME , INGEST_DOCUMENT .replace ("\" passage_text_value\" " , "null" )));
67
+ }
68
+
61
69
private String uploadModel () throws Exception {
62
70
String requestBody = Files .readString (Path .of (classLoader .getResource ("processor/UploadModelRequestBody.json" ).toURI ()));
63
71
return registerModelGroupAndUploadModel (requestBody );
0 commit comments