Skip to content

Commit 6892e0f

Browse files
committed
Introduce a new typeless HLRC method.
1 parent 19accde commit 6892e0f

21 files changed

+940
-82
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;
@@ -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;
@@ -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: 17 additions & 2 deletions
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.delete.DeleteIndexTemplateRequest;
4948
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
5049
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
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;
@@ -97,7 +97,22 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) {
9797
return request;
9898
}
9999

100-
static Request createIndex(CreateIndexRequest createIndexRequest) throws IOException {
100+
static Request createIndex(CreateIndexRequest createIndexRequest)
101+
throws IOException {
102+
String endpoint = RequestConverters.endpoint(createIndexRequest.indices());
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)