Skip to content

Commit 292e0f6

Browse files
authored
Deprecate _type in simulate pipeline requests (#37949)
As mapping types are being removed throughout Elasticsearch, the use of `_type` in pipeline simulation requests is deprecated. Additionally, the default `_type` used if one is not supplied has been changed to `_doc` for consistency with the rest of Elasticsearch.
1 parent b866417 commit 292e0f6

File tree

7 files changed

+67
-27
lines changed

7 files changed

+67
-27
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/IngestClientIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ private void testSimulatePipeline(boolean isVerbose,
130130
{
131131
builder.startObject()
132132
.field("_index", "index")
133-
.field("_type", "doc")
134133
.field("_id", "doc_" + 1)
135134
.startObject("_source").field("foo", "rab_" + 1).field("rank", rankValue).endObject()
136135
.endObject();

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ public void testSimulatePipeline() throws IOException {
296296
"\"processors\":[{\"set\":{\"field\":\"field2\",\"value\":\"_value\"}}]" +
297297
"}," +
298298
"\"docs\":[" +
299-
"{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_source\":{\"foo\":\"bar\"}}," +
300-
"{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_source\":{\"foo\":\"rab\"}}" +
299+
"{\"_index\":\"index\",\"_id\":\"id\",\"_source\":{\"foo\":\"bar\"}}," +
300+
"{\"_index\":\"index\",\"_id\":\"id\",\"_source\":{\"foo\":\"rab\"}}" +
301301
"]" +
302302
"}";
303303
SimulatePipelineRequest request = new SimulatePipelineRequest(
@@ -353,8 +353,8 @@ public void testSimulatePipelineAsync() throws Exception {
353353
"\"processors\":[{\"set\":{\"field\":\"field2\",\"value\":\"_value\"}}]" +
354354
"}," +
355355
"\"docs\":[" +
356-
"{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_source\":{\"foo\":\"bar\"}}," +
357-
"{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_source\":{\"foo\":\"rab\"}}" +
356+
"{\"_index\":\"index\",\"_id\":\"id\",\"_source\":{\"foo\":\"bar\"}}," +
357+
"{\"_index\":\"index\",\"_id\":\"id\",\"_source\":{\"foo\":\"rab\"}}" +
358358
"]" +
359359
"}";
360360
SimulatePipelineRequest request = new SimulatePipelineRequest(

docs/reference/ingest/apis/simulate-pipeline.asciidoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ POST _ingest/pipeline/_simulate
6565
"docs": [
6666
{
6767
"_index": "index",
68-
"_type": "_doc",
6968
"_id": "id",
7069
"_source": {
7170
"foo": "bar"
7271
}
7372
},
7473
{
7574
"_index": "index",
76-
"_type": "_doc",
7775
"_id": "id",
7876
"_source": {
7977
"foo": "rab"
@@ -158,15 +156,13 @@ POST _ingest/pipeline/_simulate?verbose
158156
"docs": [
159157
{
160158
"_index": "index",
161-
"_type": "_doc",
162159
"_id": "id",
163160
"_source": {
164161
"foo": "bar"
165162
}
166163
},
167164
{
168165
"_index": "index",
169-
"_type": "_doc",
170166
"_id": "id",
171167
"_source": {
172168
"foo": "rab"

docs/reference/ingest/processors/date-index-name.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ and the result:
112112
"doc" : {
113113
"_id" : "_id",
114114
"_index" : "<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>",
115-
"_type" : "_type",
115+
"_type" : "_doc",
116116
"_source" : {
117117
"date1" : "2016-04-25T12:02:01.789Z"
118118
},

docs/reference/ingest/processors/grok.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ response:
193193
"docs": [
194194
{
195195
"doc": {
196-
"_type": "_type",
196+
"_type": "_doc",
197197
"_index": "_index",
198198
"_id": "_id",
199199
"_source": {
@@ -254,7 +254,7 @@ POST _ingest/pipeline/_simulate
254254
"docs": [
255255
{
256256
"doc": {
257-
"_type": "_type",
257+
"_type": "_doc",
258258
"_index": "_index",
259259
"_id": "_id",
260260
"_source": {

server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919

2020
package org.elasticsearch.action.ingest;
2121

22+
import org.apache.logging.log4j.LogManager;
23+
import org.apache.logging.log4j.Logger;
2224
import org.elasticsearch.action.ActionRequest;
2325
import org.elasticsearch.action.ActionRequestValidationException;
2426
import org.elasticsearch.common.bytes.BytesReference;
2527
import org.elasticsearch.common.io.stream.StreamInput;
2628
import org.elasticsearch.common.io.stream.StreamOutput;
29+
import org.elasticsearch.common.logging.DeprecationLogger;
2730
import org.elasticsearch.common.xcontent.ToXContentObject;
2831
import org.elasticsearch.common.xcontent.XContentBuilder;
2932
import org.elasticsearch.common.xcontent.XContentType;
@@ -43,6 +46,9 @@
4346

4447
public class SimulatePipelineRequest extends ActionRequest implements ToXContentObject {
4548

49+
private static final Logger logger = LogManager.getLogger(SimulatePipelineRequest.class);
50+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
51+
4652
private String id;
4753
private boolean verbose;
4854
private BytesReference source;
@@ -178,8 +184,12 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
178184
dataMap, Fields.SOURCE);
179185
String index = ConfigurationUtils.readStringOrIntProperty(null, null,
180186
dataMap, MetaData.INDEX.getFieldName(), "_index");
187+
if (dataMap.containsKey(MetaData.TYPE.getFieldName())) {
188+
deprecationLogger.deprecatedAndMaybeLog("simulate_pipeline_with_types",
189+
"[types removal] specifying _type in pipeline simulation requests is deprecated");
190+
}
181191
String type = ConfigurationUtils.readStringOrIntProperty(null, null,
182-
dataMap, MetaData.TYPE.getFieldName(), "_type");
192+
dataMap, MetaData.TYPE.getFieldName(), "_doc");
183193
String id = ConfigurationUtils.readStringOrIntProperty(null, null,
184194
dataMap, MetaData.ID.getFieldName(), "_id");
185195
String routing = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,

server/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919

2020
package 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-
3122
import org.elasticsearch.index.VersionType;
3223
import org.elasticsearch.ingest.CompoundProcessor;
3324
import org.elasticsearch.ingest.IngestDocument;
@@ -38,6 +29,15 @@
3829
import org.elasticsearch.test.ESTestCase;
3930
import 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+
4141
import static org.elasticsearch.action.ingest.SimulatePipelineRequest.Fields;
4242
import static org.elasticsearch.action.ingest.SimulatePipelineRequest.SIMULATED_PIPELINE_ID;
4343
import 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

Comments
 (0)