1919
2020package org .elasticsearch .action .ingest ;
2121
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-
3122import org .elasticsearch .index .VersionType ;
3223import org .elasticsearch .ingest .CompoundProcessor ;
3324import org .elasticsearch .ingest .IngestDocument ;
3829import org .elasticsearch .test .ESTestCase ;
3930import org .junit .Before ;
4031
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+
4141import static org .elasticsearch .action .ingest .SimulatePipelineRequest .Fields ;
4242import static org .elasticsearch .action .ingest .SimulatePipelineRequest .SIMULATED_PIPELINE_ID ;
4343import static org .elasticsearch .ingest .IngestDocument .MetaData .ID ;
@@ -67,7 +67,15 @@ public void init() throws IOException {
6767 when (ingestService .getProcessorFactories ()).thenReturn (registry );
6868 }
6969
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 {
7179 int numDocs = randomIntBetween (1 , 10 );
7280
7381 Map <String , Object > requestContent = new HashMap <>();
@@ -80,15 +88,21 @@ public void testParseUsingPipelineStore() throws Exception {
8088 String type = randomAlphaOfLengthBetween (1 , 10 );
8189 String id = randomAlphaOfLengthBetween (1 , 10 );
8290 doc .put (INDEX .getFieldName (), index );
83- doc .put (TYPE .getFieldName (), type );
91+ if (useExplicitType ) {
92+ doc .put (TYPE .getFieldName (), type );
93+ }
8494 doc .put (ID .getFieldName (), id );
8595 String fieldName = randomAlphaOfLengthBetween (1 , 10 );
8696 String fieldValue = randomAlphaOfLengthBetween (1 , 10 );
8797 doc .put (Fields .SOURCE , Collections .singletonMap (fieldName , fieldValue ));
8898 docs .add (doc );
8999 Map <String , Object > expectedDoc = new HashMap <>();
90100 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+ }
92106 expectedDoc .put (ID .getFieldName (), id );
93107 expectedDoc .put (Fields .SOURCE , Collections .singletonMap (fieldName , fieldValue ));
94108 expectedDocs .add (expectedDoc );
@@ -111,9 +125,20 @@ public void testParseUsingPipelineStore() throws Exception {
111125 assertThat (actualRequest .getPipeline ().getId (), equalTo (SIMULATED_PIPELINE_ID ));
112126 assertThat (actualRequest .getPipeline ().getDescription (), nullValue ());
113127 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 );
114135 }
115136
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 {
117142 int numDocs = randomIntBetween (1 , 10 );
118143
119144 Map <String , Object > requestContent = new HashMap <>();
@@ -135,6 +160,14 @@ public void testParseWithProvidedPipeline() throws Exception {
135160 );
136161 doc .put (field .getFieldName (), value );
137162 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+ }
138171 } else {
139172 if (randomBoolean ()) {
140173 String value = randomAlphaOfLengthBetween (1 , 10 );
@@ -191,7 +224,6 @@ public void testParseWithProvidedPipeline() throws Exception {
191224 Map <String , Object > expectedDocument = expectedDocsIterator .next ();
192225 Map <IngestDocument .MetaData , Object > metadataMap = ingestDocument .extractMetadata ();
193226 assertThat (metadataMap .get (INDEX ), equalTo (expectedDocument .get (INDEX .getFieldName ())));
194- assertThat (metadataMap .get (TYPE ), equalTo (expectedDocument .get (TYPE .getFieldName ())));
195227 assertThat (metadataMap .get (ID ), equalTo (expectedDocument .get (ID .getFieldName ())));
196228 assertThat (metadataMap .get (ROUTING ), equalTo (expectedDocument .get (ROUTING .getFieldName ())));
197229 assertThat (metadataMap .get (VERSION ), equalTo (expectedDocument .get (VERSION .getFieldName ())));
@@ -202,6 +234,9 @@ public void testParseWithProvidedPipeline() throws Exception {
202234 assertThat (actualRequest .getPipeline ().getId (), equalTo (SIMULATED_PIPELINE_ID ));
203235 assertThat (actualRequest .getPipeline ().getDescription (), nullValue ());
204236 assertThat (actualRequest .getPipeline ().getProcessors ().size (), equalTo (numProcessors ));
237+ if (useExplicitType ) {
238+ assertWarnings ("[types removal] specifying _type in pipeline simulation requests is deprecated" );
239+ }
205240 }
206241
207242 public void testNullPipelineId () {
0 commit comments