Skip to content

Commit e1d8df4

Browse files
authored
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 af2f4c8 commit e1d8df4

26 files changed

+1009
-113
lines changed

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

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
2828
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
2929
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
30-
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
31-
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
3230
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3331
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3432
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
@@ -59,6 +57,8 @@
5957
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
6058
import org.elasticsearch.action.support.master.AcknowledgedResponse;
6159
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
60+
import org.elasticsearch.client.indices.CreateIndexRequest;
61+
import org.elasticsearch.client.indices.CreateIndexResponse;
6262
import org.elasticsearch.client.indices.FreezeIndexRequest;
6363
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
6464
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
@@ -120,9 +120,10 @@ public void deleteAsync(DeleteIndexRequest deleteIndexRequest, RequestOptions op
120120
* @return the response
121121
* @throws IOException in case there is a problem sending the request or parsing back the response
122122
*/
123-
public CreateIndexResponse create(CreateIndexRequest createIndexRequest, RequestOptions options) throws IOException {
123+
public CreateIndexResponse create(CreateIndexRequest createIndexRequest,
124+
RequestOptions options) throws IOException {
124125
return restHighLevelClient.performRequestAndParseEntity(createIndexRequest, IndicesRequestConverters::createIndex, options,
125-
CreateIndexResponse::fromXContent, emptySet());
126+
CreateIndexResponse::fromXContent, emptySet());
126127
}
127128

128129
/**
@@ -133,9 +134,54 @@ public CreateIndexResponse create(CreateIndexRequest createIndexRequest, Request
133134
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
134135
* @param listener the listener to be notified upon request completion
135136
*/
136-
public void createAsync(CreateIndexRequest createIndexRequest, RequestOptions options, ActionListener<CreateIndexResponse> listener) {
137+
public void createAsync(CreateIndexRequest createIndexRequest,
138+
RequestOptions options,
139+
ActionListener<CreateIndexResponse> listener) {
137140
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, IndicesRequestConverters::createIndex, options,
138-
CreateIndexResponse::fromXContent, listener, emptySet());
141+
CreateIndexResponse::fromXContent, listener, emptySet());
142+
}
143+
144+
/**
145+
* Creates an index using the Create Index API.
146+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
147+
* Create Index API on elastic.co</a>
148+
* @param createIndexRequest the request
149+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
150+
* @return the response
151+
* @throws IOException in case there is a problem sending the request or parsing back the response
152+
*
153+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
154+
* method {@link #create(CreateIndexRequest, RequestOptions)} should be used instead, which accepts a new
155+
* request object.
156+
*/
157+
@Deprecated
158+
public org.elasticsearch.action.admin.indices.create.CreateIndexResponse create(
159+
org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest,
160+
RequestOptions options) throws IOException {
161+
return restHighLevelClient.performRequestAndParseEntity(createIndexRequest,
162+
IndicesRequestConverters::createIndex, options,
163+
org.elasticsearch.action.admin.indices.create.CreateIndexResponse::fromXContent, emptySet());
164+
}
165+
166+
/**
167+
* Asynchronously creates an index using the Create Index API.
168+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
169+
* Create Index API on elastic.co</a>
170+
* @param createIndexRequest the request
171+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
172+
* @param listener the listener to be notified upon request completion
173+
*
174+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
175+
* method {@link #createAsync(CreateIndexRequest, RequestOptions, ActionListener)} should be used instead,
176+
* which accepts a new request object.
177+
*/
178+
@Deprecated
179+
public void createAsync(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest,
180+
RequestOptions options,
181+
ActionListener<org.elasticsearch.action.admin.indices.create.CreateIndexResponse> listener) {
182+
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest,
183+
IndicesRequestConverters::createIndex, options,
184+
org.elasticsearch.action.admin.indices.create.CreateIndexResponse::fromXContent, listener, emptySet());
139185
}
140186

141187
/**

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;
@@ -47,6 +46,7 @@
4746
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
4847
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
4948
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
49+
import org.elasticsearch.client.indices.CreateIndexRequest;
5050
import org.elasticsearch.client.indices.FreezeIndexRequest;
5151
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
5252
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
@@ -98,6 +98,21 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) {
9898
}
9999

100100
static Request createIndex(CreateIndexRequest createIndexRequest) throws IOException {
101+
String endpoint = new RequestConverters.EndpointBuilder()
102+
.addPathPart(createIndexRequest.index()).build();
103+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
104+
105+
RequestConverters.Params parameters = new RequestConverters.Params(request);
106+
parameters.withTimeout(createIndexRequest.timeout());
107+
parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout());
108+
parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards());
109+
110+
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
111+
return request;
112+
}
113+
114+
static Request createIndex(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest)
115+
throws IOException {
101116
String endpoint = RequestConverters.endpoint(createIndexRequest.indices());
102117
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
103118

0 commit comments

Comments
 (0)