Skip to content

Commit 1bebc05

Browse files
committed
Deprecate types in create index requests. (#37134)
From #29453 and #37285, the include_type_name parameter was already present and defaulted to false. 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 40d0c17 commit 1bebc05

26 files changed

+1035
-129
lines changed

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

Lines changed: 65 additions & 10 deletions
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

Lines changed: 16 additions & 1 deletion
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,6 +99,21 @@ 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+
111+
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
112+
return request;
113+
}
114+
115+
static Request createIndex(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest)
116+
throws IOException {
102117
String endpoint = RequestConverters.endpoint(createIndexRequest.indices());
103118
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
104119

0 commit comments

Comments
 (0)