|
@@ -19,15 +19,6 @@
|
|
|
|
|
|
package org.elasticsearch.action.ingest;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
import org.elasticsearch.index.VersionType;
|
|
|
import org.elasticsearch.ingest.CompoundProcessor;
|
|
|
import org.elasticsearch.ingest.IngestDocument;
|
|
@@ -38,6 +29,15 @@ import org.elasticsearch.ingest.TestProcessor;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.junit.Before;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
import static org.elasticsearch.action.ingest.SimulatePipelineRequest.Fields;
|
|
|
import static org.elasticsearch.action.ingest.SimulatePipelineRequest.SIMULATED_PIPELINE_ID;
|
|
|
import static org.elasticsearch.ingest.IngestDocument.MetaData.ID;
|
|
@@ -67,7 +67,15 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
when(ingestService.getProcessorFactories()).thenReturn(registry);
|
|
|
}
|
|
|
|
|
|
- public void testParseUsingPipelineStore() throws Exception {
|
|
|
+ public void testParseUsingPipelineStoreNoType() throws Exception {
|
|
|
+ innerTestParseUsingPipelineStore(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testParseUsingPipelineStoreWithType() throws Exception {
|
|
|
+ innerTestParseUsingPipelineStore(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void innerTestParseUsingPipelineStore(boolean useExplicitType) throws Exception {
|
|
|
int numDocs = randomIntBetween(1, 10);
|
|
|
|
|
|
Map<String, Object> requestContent = new HashMap<>();
|
|
@@ -80,7 +88,9 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
String type = randomAlphaOfLengthBetween(1, 10);
|
|
|
String id = randomAlphaOfLengthBetween(1, 10);
|
|
|
doc.put(INDEX.getFieldName(), index);
|
|
|
- doc.put(TYPE.getFieldName(), type);
|
|
|
+ if (useExplicitType) {
|
|
|
+ doc.put(TYPE.getFieldName(), type);
|
|
|
+ }
|
|
|
doc.put(ID.getFieldName(), id);
|
|
|
String fieldName = randomAlphaOfLengthBetween(1, 10);
|
|
|
String fieldValue = randomAlphaOfLengthBetween(1, 10);
|
|
@@ -88,7 +98,11 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
docs.add(doc);
|
|
|
Map<String, Object> expectedDoc = new HashMap<>();
|
|
|
expectedDoc.put(INDEX.getFieldName(), index);
|
|
|
- expectedDoc.put(TYPE.getFieldName(), type);
|
|
|
+ if (useExplicitType) {
|
|
|
+ expectedDoc.put(TYPE.getFieldName(), type);
|
|
|
+ } else {
|
|
|
+ expectedDoc.put(TYPE.getFieldName(), "_doc");
|
|
|
+ }
|
|
|
expectedDoc.put(ID.getFieldName(), id);
|
|
|
expectedDoc.put(Fields.SOURCE, Collections.singletonMap(fieldName, fieldValue));
|
|
|
expectedDocs.add(expectedDoc);
|
|
@@ -111,9 +125,20 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID));
|
|
|
assertThat(actualRequest.getPipeline().getDescription(), nullValue());
|
|
|
assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(1));
|
|
|
+ if (useExplicitType) {
|
|
|
+ assertWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testParseWithProvidedPipelineNoType() throws Exception {
|
|
|
+ innerTestParseWithProvidedPipeline(false);
|
|
|
}
|
|
|
|
|
|
- public void testParseWithProvidedPipeline() throws Exception {
|
|
|
+ public void testParseWithProvidedPipelineWithType() throws Exception {
|
|
|
+ innerTestParseWithProvidedPipeline(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws Exception {
|
|
|
int numDocs = randomIntBetween(1, 10);
|
|
|
|
|
|
Map<String, Object> requestContent = new HashMap<>();
|
|
@@ -135,6 +160,14 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
);
|
|
|
doc.put(field.getFieldName(), value);
|
|
|
expectedDoc.put(field.getFieldName(), value);
|
|
|
+ } else if (field == TYPE) {
|
|
|
+ if (useExplicitType) {
|
|
|
+ String value = randomAlphaOfLengthBetween(1, 10);
|
|
|
+ doc.put(field.getFieldName(), value);
|
|
|
+ expectedDoc.put(field.getFieldName(), value);
|
|
|
+ } else {
|
|
|
+ expectedDoc.put(field.getFieldName(), "_doc");
|
|
|
+ }
|
|
|
} else {
|
|
|
if (randomBoolean()) {
|
|
|
String value = randomAlphaOfLengthBetween(1, 10);
|
|
@@ -191,7 +224,6 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
Map<String, Object> expectedDocument = expectedDocsIterator.next();
|
|
|
Map<IngestDocument.MetaData, Object> metadataMap = ingestDocument.extractMetadata();
|
|
|
assertThat(metadataMap.get(INDEX), equalTo(expectedDocument.get(INDEX.getFieldName())));
|
|
|
- assertThat(metadataMap.get(TYPE), equalTo(expectedDocument.get(TYPE.getFieldName())));
|
|
|
assertThat(metadataMap.get(ID), equalTo(expectedDocument.get(ID.getFieldName())));
|
|
|
assertThat(metadataMap.get(ROUTING), equalTo(expectedDocument.get(ROUTING.getFieldName())));
|
|
|
assertThat(metadataMap.get(VERSION), equalTo(expectedDocument.get(VERSION.getFieldName())));
|
|
@@ -202,6 +234,9 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|
|
assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID));
|
|
|
assertThat(actualRequest.getPipeline().getDescription(), nullValue());
|
|
|
assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(numProcessors));
|
|
|
+ if (useExplicitType) {
|
|
|
+ assertWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void testNullPipelineId() {
|