Skip to content

Commit 14adf8a

Browse files
authored
Deprecate types in create index requests (backport to 6.x). (#37838)
From previous PRs, the include_type_name parameter was already present. This PR makes the following updates: * Add deprecation warnings to RestCreateIndexAction, plus tests in RestCreateIndexActionTests. * Add a typeless 'create index' method to the Java HLRC, and deprecate the old typed version. To do this cleanly, I created new CreateIndexRequest and CreateIndexResponse objects that differ from the existing server ones.
1 parent 3ae70c6 commit 14adf8a

26 files changed

+1098
-169
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

+65-10
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
2929
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
3030
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
31-
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
32-
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
3331
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3432
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3533
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
@@ -60,6 +58,8 @@
6058
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
6159
import org.elasticsearch.action.support.master.AcknowledgedResponse;
6260
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
61+
import org.elasticsearch.client.indices.CreateIndexRequest;
62+
import org.elasticsearch.client.indices.CreateIndexResponse;
6363
import org.elasticsearch.client.indices.FreezeIndexRequest;
6464
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
6565
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
@@ -147,24 +147,52 @@ public void deleteAsync(DeleteIndexRequest deleteIndexRequest, ActionListener<Ac
147147
* @return the response
148148
* @throws IOException in case there is a problem sending the request or parsing back the response
149149
*/
150-
public CreateIndexResponse create(CreateIndexRequest createIndexRequest, RequestOptions options) throws IOException {
150+
public CreateIndexResponse create(CreateIndexRequest createIndexRequest,
151+
RequestOptions options) throws IOException {
151152
return restHighLevelClient.performRequestAndParseEntity(createIndexRequest, IndicesRequestConverters::createIndex, options,
152-
CreateIndexResponse::fromXContent, emptySet());
153+
CreateIndexResponse::fromXContent, emptySet());
153154
}
154155

155156
/**
156157
* Creates an index using the Create Index API.
157158
* <p>
158159
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
159160
* Create Index API on elastic.co</a>
160-
* @deprecated Prefer {@link #create(CreateIndexRequest, RequestOptions)}
161+
*
162+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
163+
* method {@link #create(CreateIndexRequest, RequestOptions)} should be used instead, which accepts a new
164+
* request object and also uses request options instead of headers.
161165
*/
162166
@Deprecated
163-
public CreateIndexResponse create(CreateIndexRequest createIndexRequest, Header... headers) throws IOException {
167+
public CreateIndexResponse create(
168+
org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest,
169+
Header... headers) throws IOException {
164170
return restHighLevelClient.performRequestAndParseEntity(createIndexRequest, IndicesRequestConverters::createIndex,
165171
CreateIndexResponse::fromXContent, emptySet(), headers);
166172
}
167173

174+
/**
175+
* Creates an index using the Create Index API.
176+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
177+
* Create Index API on elastic.co</a>
178+
* @param createIndexRequest the request
179+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
180+
* @return the response
181+
* @throws IOException in case there is a problem sending the request or parsing back the response
182+
*
183+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
184+
* method {@link #create(CreateIndexRequest, RequestOptions)} should be used instead, which accepts a new
185+
* request object.
186+
*/
187+
@Deprecated
188+
public org.elasticsearch.action.admin.indices.create.CreateIndexResponse create(
189+
org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest,
190+
RequestOptions options) throws IOException {
191+
return restHighLevelClient.performRequestAndParseEntity(createIndexRequest,
192+
IndicesRequestConverters::createIndex, options,
193+
org.elasticsearch.action.admin.indices.create.CreateIndexResponse::fromXContent, emptySet());
194+
}
195+
168196
/**
169197
* Asynchronously creates an index using the Create Index API.
170198
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
@@ -173,20 +201,47 @@ public CreateIndexResponse create(CreateIndexRequest createIndexRequest, Header.
173201
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
174202
* @param listener the listener to be notified upon request completion
175203
*/
176-
public void createAsync(CreateIndexRequest createIndexRequest, RequestOptions options, ActionListener<CreateIndexResponse> listener) {
204+
public void createAsync(CreateIndexRequest createIndexRequest,
205+
RequestOptions options,
206+
ActionListener<CreateIndexResponse> listener) {
177207
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, IndicesRequestConverters::createIndex, options,
178-
CreateIndexResponse::fromXContent, listener, emptySet());
208+
CreateIndexResponse::fromXContent, listener, emptySet());
209+
}
210+
211+
/**
212+
* Asynchronously creates an index using the Create Index API.
213+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
214+
* Create Index API on elastic.co</a>
215+
* @param createIndexRequest the request
216+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
217+
* @param listener the listener to be notified upon request completion
218+
*
219+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
220+
* method {@link #createAsync(CreateIndexRequest, RequestOptions, ActionListener)} should be used instead,
221+
* which accepts a new request object.
222+
*/
223+
@Deprecated
224+
public void createAsync(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest,
225+
RequestOptions options,
226+
ActionListener<org.elasticsearch.action.admin.indices.create.CreateIndexResponse> listener) {
227+
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest,
228+
IndicesRequestConverters::createIndex, options,
229+
org.elasticsearch.action.admin.indices.create.CreateIndexResponse::fromXContent, listener, emptySet());
179230
}
180231

181232
/**
182233
* Asynchronously creates an index using the Create Index API.
183234
* <p>
184235
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
185236
* Create Index API on elastic.co</a>
186-
* @deprecated Prefer {@link #createAsync(CreateIndexRequest, RequestOptions, ActionListener)}
237+
*
238+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
239+
* method {@link #createAsync(CreateIndexRequest, RequestOptions, ActionListener)} should be used instead,
240+
* which accepts a new request object and also uses request objects instead of headers.
187241
*/
188242
@Deprecated
189-
public void createAsync(CreateIndexRequest createIndexRequest, ActionListener<CreateIndexResponse> listener, Header... headers) {
243+
public void createAsync(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest,
244+
ActionListener<CreateIndexResponse> listener, Header... headers) {
190245
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, IndicesRequestConverters::createIndex,
191246
CreateIndexResponse::fromXContent, listener, emptySet(), headers);
192247
}

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
3030
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
3131
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
32-
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
3332
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3433
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3534
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
@@ -48,6 +47,7 @@
4847
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
4948
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
5049
import org.elasticsearch.action.support.ActiveShardCount;
50+
import org.elasticsearch.client.indices.CreateIndexRequest;
5151
import org.elasticsearch.client.indices.FreezeIndexRequest;
5252
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
5353
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
@@ -99,13 +99,30 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) {
9999
}
100100

101101
static Request createIndex(CreateIndexRequest createIndexRequest) throws IOException {
102+
String endpoint = new RequestConverters.EndpointBuilder()
103+
.addPathPart(createIndexRequest.index()).build();
104+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
105+
106+
RequestConverters.Params parameters = new RequestConverters.Params(request);
107+
parameters.withTimeout(createIndexRequest.timeout());
108+
parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout());
109+
parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards(), ActiveShardCount.DEFAULT);
110+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "false");
111+
112+
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
113+
return request;
114+
}
115+
116+
static Request createIndex(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest)
117+
throws IOException {
102118
String endpoint = RequestConverters.endpoint(createIndexRequest.indices());
103119
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
104120

105121
RequestConverters.Params parameters = new RequestConverters.Params(request);
106122
parameters.withTimeout(createIndexRequest.timeout());
107123
parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout());
108124
parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards(), ActiveShardCount.DEFAULT);
125+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
109126

110127
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
111128
return request;
@@ -146,6 +163,7 @@ static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.Put
146163
RequestConverters.Params parameters = new RequestConverters.Params(request);
147164
parameters.withTimeout(putMappingRequest.timeout());
148165
parameters.withMasterTimeout(putMappingRequest.masterNodeTimeout());
166+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
149167

150168
request.setEntity(RequestConverters.createEntity(putMappingRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
151169
return request;
@@ -202,6 +220,8 @@ static Request getFieldMapping(org.elasticsearch.action.admin.indices.mapping.ge
202220
parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
203221
parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
204222
parameters.withLocal(getFieldMappingsRequest.local());
223+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
224+
205225
return request;
206226
}
207227

0 commit comments

Comments
 (0)