Skip to content

Commit d255303

Browse files
author
Christoph Büscher
authored
Add typless client side GetIndexRequest calls and response class (#37778)
The HLRC client currently uses `org.elasticsearch.action.admin.indices.get.GetIndexRequest` and `org.elasticsearch.action.admin.indices.get.GetIndexResponse` in its get index calls. Both request and response are designed for the typed APIs, including some return types e.g. for `getMappings()` which in the maps it returns still use a level including the type name. In order to change this without breaking existing users of the HLRC API, this PR introduces two new request and response objects in the `org.elasticsearch.client.indices` client package. These are used by the IndicesClient#get and IndicesClient#exists calls now by default and support the type-less API. The old request and response objects are still kept for use in similarly named, but deprecated methods. The newly introduced client side classes are simplified versions of the server side request/response classes since they don't need to support wire serialization, and only the response needs fromXContent parsing (but no xContent-serialization, since this is the responsibility of the server-side class). Also changing the return type of `GetIndexResponse#getMapping` to `Map<String, MappingMetaData> getMappings()`, while it previously was returning another map keyed by the type-name. Similar getters return simple Maps instead of the ImmutableOpenMaps that the server side response objects return.
1 parent 9d3f057 commit d255303

File tree

16 files changed

+990
-144
lines changed

16 files changed

+990
-144
lines changed

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

Lines changed: 101 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
3434
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
3535
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
36-
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
37-
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
38-
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
39-
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
4036
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
4137
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
4238
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
@@ -54,10 +50,14 @@
5450
import org.elasticsearch.client.indices.CreateIndexRequest;
5551
import org.elasticsearch.client.indices.CreateIndexResponse;
5652
import org.elasticsearch.client.indices.FreezeIndexRequest;
53+
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
54+
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
55+
import org.elasticsearch.client.indices.GetIndexRequest;
56+
import org.elasticsearch.client.indices.GetIndexResponse;
5757
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
58+
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
5859
import org.elasticsearch.client.indices.GetMappingsRequest;
5960
import org.elasticsearch.client.indices.GetMappingsResponse;
60-
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
6161
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
6262
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
6363
import org.elasticsearch.client.indices.PutMappingRequest;
@@ -649,6 +649,41 @@ public void getAsync(GetIndexRequest getIndexRequest, RequestOptions options,
649649
GetIndexResponse::fromXContent, listener, emptySet());
650650
}
651651

652+
/**
653+
* Retrieve information about one or more indexes
654+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
655+
* Indices Get Index API on elastic.co</a>
656+
* @param getIndexRequest the request
657+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
658+
* @return the response
659+
* @throws IOException in case there is a problem sending the request or parsing back the response
660+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
661+
* {@link #get(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object.
662+
*/
663+
@Deprecated
664+
public org.elasticsearch.action.admin.indices.get.GetIndexResponse get(
665+
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options) throws IOException {
666+
return restHighLevelClient.performRequestAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options,
667+
org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, emptySet());
668+
}
669+
670+
/**
671+
* Retrieve information about one or more indexes
672+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
673+
* Indices Get Index API on elastic.co</a>
674+
* @param getIndexRequest the request
675+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
676+
* @param listener the listener to be notified upon request completion
677+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
678+
* {@link #getAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object.
679+
*/
680+
@Deprecated
681+
public void getAsync(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options,
682+
ActionListener<org.elasticsearch.action.admin.indices.get.GetIndexResponse> listener) {
683+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options,
684+
org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, listener, emptySet());
685+
}
686+
652687
/**
653688
* Force merge one or more indices using the Force Merge API.
654689
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
@@ -772,6 +807,51 @@ public void existsAsync(GetIndexRequest request, RequestOptions options, ActionL
772807
);
773808
}
774809

810+
/**
811+
* Checks if the index (indices) exists or not.
812+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html">
813+
* Indices Exists API on elastic.co</a>
814+
* @param request the request
815+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
816+
* @return the response
817+
* @throws IOException in case there is a problem sending the request
818+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
819+
* {@link #exists(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object.
820+
*/
821+
@Deprecated
822+
public boolean exists(org.elasticsearch.action.admin.indices.get.GetIndexRequest request, RequestOptions options) throws IOException {
823+
return restHighLevelClient.performRequest(
824+
request,
825+
IndicesRequestConverters::indicesExist,
826+
options,
827+
RestHighLevelClient::convertExistsResponse,
828+
Collections.emptySet()
829+
);
830+
}
831+
832+
/**
833+
* Asynchronously checks if the index (indices) exists or not.
834+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html">
835+
* Indices Exists API on elastic.co</a>
836+
* @param request the request
837+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
838+
* @param listener the listener to be notified upon request completion
839+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
840+
* {@link #existsAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object.
841+
*/
842+
@Deprecated
843+
public void existsAsync(org.elasticsearch.action.admin.indices.get.GetIndexRequest request, RequestOptions options,
844+
ActionListener<Boolean> listener) {
845+
restHighLevelClient.performRequestAsync(
846+
request,
847+
IndicesRequestConverters::indicesExist,
848+
options,
849+
RestHighLevelClient::convertExistsResponse,
850+
listener,
851+
Collections.emptySet()
852+
);
853+
}
854+
775855
/**
776856
* Shrinks an index using the Shrink Index API.
777857
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shrink-index.html">
@@ -948,7 +1028,7 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Reques
9481028
AcknowledgedResponse::fromXContent, listener, emptySet());
9491029
}
9501030

951-
1031+
9521032
/**
9531033
* Puts an index template using the Index Templates API.
9541034
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
@@ -957,7 +1037,7 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Reques
9571037
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
9581038
* @return the response
9591039
* @throws IOException in case there is a problem sending the request or parsing back the response
960-
* @deprecated This old form of request allows types in mappings. Use {@link #putTemplate(PutIndexTemplateRequest, RequestOptions)}
1040+
* @deprecated This old form of request allows types in mappings. Use {@link #putTemplate(PutIndexTemplateRequest, RequestOptions)}
9611041
* instead which introduces a new request object without types.
9621042
*/
9631043
@Deprecated
@@ -975,18 +1055,18 @@ public AcknowledgedResponse putTemplate(
9751055
* @param putIndexTemplateRequest the request
9761056
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
9771057
* @param listener the listener to be notified upon request completion
978-
* @deprecated This old form of request allows types in mappings.
979-
* Use {@link #putTemplateAsync(PutIndexTemplateRequest, RequestOptions, ActionListener)}
1058+
* @deprecated This old form of request allows types in mappings.
1059+
* Use {@link #putTemplateAsync(PutIndexTemplateRequest, RequestOptions, ActionListener)}
9801060
* instead which introduces a new request object without types.
9811061
*/
9821062
@Deprecated
983-
public void putTemplateAsync(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
1063+
public void putTemplateAsync(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
9841064
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
9851065
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
9861066
AcknowledgedResponse::fromXContent, listener, emptySet());
9871067
}
988-
989-
1068+
1069+
9901070
/**
9911071
* Puts an index template using the Index Templates API.
9921072
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
@@ -1011,7 +1091,7 @@ public AcknowledgedResponse putTemplate(
10111091
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
10121092
* @param listener the listener to be notified upon request completion
10131093
*/
1014-
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
1094+
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
10151095
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
10161096
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
10171097
AcknowledgedResponse::fromXContent, listener, emptySet());
@@ -1056,7 +1136,7 @@ public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, Reques
10561136
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
10571137
* @return the response
10581138
* @throws IOException in case there is a problem sending the request or parsing back the response
1059-
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
1139+
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
10601140
* {@link #getIndexTemplate(GetIndexTemplatesRequest, RequestOptions)} instead which returns a new response object
10611141
*/
10621142
@Deprecated
@@ -1066,7 +1146,7 @@ public org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResp
10661146
IndicesRequestConverters::getTemplatesWithDocumentTypes,
10671147
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, emptySet());
10681148
}
1069-
1149+
10701150
/**
10711151
* Gets index templates using the Index Templates API
10721152
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
@@ -1081,17 +1161,17 @@ public GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIn
10811161
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
10821162
IndicesRequestConverters::getTemplates,
10831163
options, GetIndexTemplatesResponse::fromXContent, emptySet());
1084-
}
1164+
}
10851165

10861166
/**
1087-
* Asynchronously gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format,
1167+
* Asynchronously gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format,
10881168
* where the mapping definition is nested under the type name.
10891169
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
10901170
* on elastic.co</a>
10911171
* @param getIndexTemplatesRequest the request
10921172
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
10931173
* @param listener the listener to be notified upon request completion
1094-
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
1174+
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
10951175
* {@link #getIndexTemplateAsync(GetIndexTemplatesRequest, RequestOptions, ActionListener)} instead which returns a new response object
10961176
*/
10971177
@Deprecated
@@ -1101,7 +1181,7 @@ public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest,
11011181
IndicesRequestConverters::getTemplatesWithDocumentTypes,
11021182
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, listener, emptySet());
11031183
}
1104-
1184+
11051185
/**
11061186
* Asynchronously gets index templates using the Index Templates API
11071187
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
@@ -1110,12 +1190,12 @@ public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest,
11101190
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
11111191
* @param listener the listener to be notified upon request completion
11121192
*/
1113-
public void getIndexTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
1193+
public void getIndexTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
11141194
ActionListener<GetIndexTemplatesResponse> listener) {
11151195
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
11161196
IndicesRequestConverters::getTemplates,
11171197
options, GetIndexTemplatesResponse::fromXContent, listener, emptySet());
1118-
}
1198+
}
11191199

11201200
/**
11211201
* Uses the Index Templates API to determine if index templates exist

0 commit comments

Comments
 (0)