19
19
20
20
package org .elasticsearch .action .ingest ;
21
21
22
- import java .io .IOException ;
23
- import java .util .ArrayList ;
24
- import java .util .Arrays ;
25
- import java .util .Collections ;
26
- import java .util .HashMap ;
27
- import java .util .Iterator ;
28
- import java .util .List ;
29
- import java .util .Map ;
30
-
31
22
import org .elasticsearch .index .VersionType ;
32
23
import org .elasticsearch .ingest .CompoundProcessor ;
33
24
import org .elasticsearch .ingest .IngestDocument ;
38
29
import org .elasticsearch .test .ESTestCase ;
39
30
import org .junit .Before ;
40
31
32
+ import java .io .IOException ;
33
+ import java .util .ArrayList ;
34
+ import java .util .Arrays ;
35
+ import java .util .Collections ;
36
+ import java .util .HashMap ;
37
+ import java .util .Iterator ;
38
+ import java .util .List ;
39
+ import java .util .Map ;
40
+
41
41
import static org .elasticsearch .action .ingest .SimulatePipelineRequest .Fields ;
42
42
import static org .elasticsearch .action .ingest .SimulatePipelineRequest .SIMULATED_PIPELINE_ID ;
43
43
import static org .elasticsearch .ingest .IngestDocument .MetaData .ID ;
@@ -67,7 +67,15 @@ public void init() throws IOException {
67
67
when (ingestService .getProcessorFactories ()).thenReturn (registry );
68
68
}
69
69
70
- public void testParseUsingPipelineStore () throws Exception {
70
+ public void testParseUsingPipelineStoreNoType () throws Exception {
71
+ innerTestParseUsingPipelineStore (false );
72
+ }
73
+
74
+ public void testParseUsingPipelineStoreWithType () throws Exception {
75
+ innerTestParseUsingPipelineStore (true );
76
+ }
77
+
78
+ private void innerTestParseUsingPipelineStore (boolean useExplicitType ) throws Exception {
71
79
int numDocs = randomIntBetween (1 , 10 );
72
80
73
81
Map <String , Object > requestContent = new HashMap <>();
@@ -80,15 +88,21 @@ public void testParseUsingPipelineStore() throws Exception {
80
88
String type = randomAlphaOfLengthBetween (1 , 10 );
81
89
String id = randomAlphaOfLengthBetween (1 , 10 );
82
90
doc .put (INDEX .getFieldName (), index );
83
- doc .put (TYPE .getFieldName (), type );
91
+ if (useExplicitType ) {
92
+ doc .put (TYPE .getFieldName (), type );
93
+ }
84
94
doc .put (ID .getFieldName (), id );
85
95
String fieldName = randomAlphaOfLengthBetween (1 , 10 );
86
96
String fieldValue = randomAlphaOfLengthBetween (1 , 10 );
87
97
doc .put (Fields .SOURCE , Collections .singletonMap (fieldName , fieldValue ));
88
98
docs .add (doc );
89
99
Map <String , Object > expectedDoc = new HashMap <>();
90
100
expectedDoc .put (INDEX .getFieldName (), index );
91
- expectedDoc .put (TYPE .getFieldName (), type );
101
+ if (useExplicitType ) {
102
+ expectedDoc .put (TYPE .getFieldName (), type );
103
+ } else {
104
+ expectedDoc .put (TYPE .getFieldName (), "_doc" );
105
+ }
92
106
expectedDoc .put (ID .getFieldName (), id );
93
107
expectedDoc .put (Fields .SOURCE , Collections .singletonMap (fieldName , fieldValue ));
94
108
expectedDocs .add (expectedDoc );
@@ -111,9 +125,20 @@ public void testParseUsingPipelineStore() throws Exception {
111
125
assertThat (actualRequest .getPipeline ().getId (), equalTo (SIMULATED_PIPELINE_ID ));
112
126
assertThat (actualRequest .getPipeline ().getDescription (), nullValue ());
113
127
assertThat (actualRequest .getPipeline ().getProcessors ().size (), equalTo (1 ));
128
+ if (useExplicitType ) {
129
+ assertWarnings ("[types removal] specifying _type in pipeline simulation requests is deprecated" );
130
+ }
131
+ }
132
+
133
+ public void testParseWithProvidedPipelineNoType () throws Exception {
134
+ innerTestParseWithProvidedPipeline (false );
114
135
}
115
136
116
- public void testParseWithProvidedPipeline () throws Exception {
137
+ public void testParseWithProvidedPipelineWithType () throws Exception {
138
+ innerTestParseWithProvidedPipeline (true );
139
+ }
140
+
141
+ private void innerTestParseWithProvidedPipeline (boolean useExplicitType ) throws Exception {
117
142
int numDocs = randomIntBetween (1 , 10 );
118
143
119
144
Map <String , Object > requestContent = new HashMap <>();
@@ -135,6 +160,14 @@ public void testParseWithProvidedPipeline() throws Exception {
135
160
);
136
161
doc .put (field .getFieldName (), value );
137
162
expectedDoc .put (field .getFieldName (), value );
163
+ } else if (field == TYPE ) {
164
+ if (useExplicitType ) {
165
+ String value = randomAlphaOfLengthBetween (1 , 10 );
166
+ doc .put (field .getFieldName (), value );
167
+ expectedDoc .put (field .getFieldName (), value );
168
+ } else {
169
+ expectedDoc .put (field .getFieldName (), "_doc" );
170
+ }
138
171
} else {
139
172
if (randomBoolean ()) {
140
173
String value = randomAlphaOfLengthBetween (1 , 10 );
@@ -191,7 +224,6 @@ public void testParseWithProvidedPipeline() throws Exception {
191
224
Map <String , Object > expectedDocument = expectedDocsIterator .next ();
192
225
Map <IngestDocument .MetaData , Object > metadataMap = ingestDocument .extractMetadata ();
193
226
assertThat (metadataMap .get (INDEX ), equalTo (expectedDocument .get (INDEX .getFieldName ())));
194
- assertThat (metadataMap .get (TYPE ), equalTo (expectedDocument .get (TYPE .getFieldName ())));
195
227
assertThat (metadataMap .get (ID ), equalTo (expectedDocument .get (ID .getFieldName ())));
196
228
assertThat (metadataMap .get (ROUTING ), equalTo (expectedDocument .get (ROUTING .getFieldName ())));
197
229
assertThat (metadataMap .get (VERSION ), equalTo (expectedDocument .get (VERSION .getFieldName ())));
@@ -202,6 +234,9 @@ public void testParseWithProvidedPipeline() throws Exception {
202
234
assertThat (actualRequest .getPipeline ().getId (), equalTo (SIMULATED_PIPELINE_ID ));
203
235
assertThat (actualRequest .getPipeline ().getDescription (), nullValue ());
204
236
assertThat (actualRequest .getPipeline ().getProcessors ().size (), equalTo (numProcessors ));
237
+ if (useExplicitType ) {
238
+ assertWarnings ("[types removal] specifying _type in pipeline simulation requests is deprecated" );
239
+ }
205
240
}
206
241
207
242
public void testNullPipelineId () {
0 commit comments