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.
This commit is contained in:
parent
9d3f057894
commit
d255303584
|
@ -33,10 +33,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
||||||
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
|
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
|
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
||||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||||
|
@ -54,10 +50,14 @@ import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
|
||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||||
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
|
||||||
import org.elasticsearch.client.indices.GetMappingsRequest;
|
import org.elasticsearch.client.indices.GetMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.GetMappingsResponse;
|
import org.elasticsearch.client.indices.GetMappingsResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
|
|
||||||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
||||||
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
||||||
import org.elasticsearch.client.indices.PutMappingRequest;
|
import org.elasticsearch.client.indices.PutMappingRequest;
|
||||||
|
@ -649,6 +649,41 @@ public final class IndicesClient {
|
||||||
GetIndexResponse::fromXContent, listener, emptySet());
|
GetIndexResponse::fromXContent, listener, emptySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve information about one or more indexes
|
||||||
|
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
|
||||||
|
* Indices Get Index API on elastic.co</a>
|
||||||
|
* @param getIndexRequest the request
|
||||||
|
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||||
|
* @return the response
|
||||||
|
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||||
|
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
|
||||||
|
* {@link #get(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public org.elasticsearch.action.admin.indices.get.GetIndexResponse get(
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options) throws IOException {
|
||||||
|
return restHighLevelClient.performRequestAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options,
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve information about one or more indexes
|
||||||
|
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
|
||||||
|
* Indices Get Index API on elastic.co</a>
|
||||||
|
* @param getIndexRequest the request
|
||||||
|
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||||
|
* @param listener the listener to be notified upon request completion
|
||||||
|
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
|
||||||
|
* {@link #getAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void getAsync(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options,
|
||||||
|
ActionListener<org.elasticsearch.action.admin.indices.get.GetIndexResponse> listener) {
|
||||||
|
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options,
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, listener, emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force merge one or more indices using the Force Merge API.
|
* Force merge one or more indices using the Force Merge API.
|
||||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
|
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
|
||||||
|
@ -772,6 +807,51 @@ public final class IndicesClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the index (indices) exists or not.
|
||||||
|
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html">
|
||||||
|
* Indices Exists API on elastic.co</a>
|
||||||
|
* @param request the request
|
||||||
|
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||||
|
* @return the response
|
||||||
|
* @throws IOException in case there is a problem sending the request
|
||||||
|
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
|
||||||
|
* {@link #exists(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public boolean exists(org.elasticsearch.action.admin.indices.get.GetIndexRequest request, RequestOptions options) throws IOException {
|
||||||
|
return restHighLevelClient.performRequest(
|
||||||
|
request,
|
||||||
|
IndicesRequestConverters::indicesExist,
|
||||||
|
options,
|
||||||
|
RestHighLevelClient::convertExistsResponse,
|
||||||
|
Collections.emptySet()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously checks if the index (indices) exists or not.
|
||||||
|
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html">
|
||||||
|
* Indices Exists API on elastic.co</a>
|
||||||
|
* @param request the request
|
||||||
|
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||||
|
* @param listener the listener to be notified upon request completion
|
||||||
|
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
|
||||||
|
* {@link #existsAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void existsAsync(org.elasticsearch.action.admin.indices.get.GetIndexRequest request, RequestOptions options,
|
||||||
|
ActionListener<Boolean> listener) {
|
||||||
|
restHighLevelClient.performRequestAsync(
|
||||||
|
request,
|
||||||
|
IndicesRequestConverters::indicesExist,
|
||||||
|
options,
|
||||||
|
RestHighLevelClient::convertExistsResponse,
|
||||||
|
listener,
|
||||||
|
Collections.emptySet()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shrinks an index using the Shrink Index API.
|
* Shrinks an index using the Shrink Index API.
|
||||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shrink-index.html">
|
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shrink-index.html">
|
||||||
|
|
|
@ -33,8 +33,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
|
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
|
||||||
|
@ -45,6 +43,8 @@ import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplat
|
||||||
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
|
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
|
||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||||
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
||||||
import org.elasticsearch.client.indices.GetMappingsRequest;
|
import org.elasticsearch.client.indices.GetMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
||||||
|
@ -148,6 +148,10 @@ final class IndicesRequestConverters {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converter for the legacy server-side {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} that still supports
|
||||||
|
* types
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) throws IOException {
|
static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) throws IOException {
|
||||||
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
|
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
|
||||||
|
@ -389,6 +393,28 @@ final class IndicesRequestConverters {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converter for the legacy server-side {@link org.elasticsearch.action.admin.indices.get.GetIndexRequest} that
|
||||||
|
* still supports types
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
static Request getIndex(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest) {
|
||||||
|
String[] indices = getIndexRequest.indices() == null ? Strings.EMPTY_ARRAY : getIndexRequest.indices();
|
||||||
|
|
||||||
|
String endpoint = RequestConverters.endpoint(indices);
|
||||||
|
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||||
|
|
||||||
|
RequestConverters.Params params = new RequestConverters.Params(request);
|
||||||
|
params.withIndicesOptions(getIndexRequest.indicesOptions());
|
||||||
|
params.withLocal(getIndexRequest.local());
|
||||||
|
params.withIncludeDefaults(getIndexRequest.includeDefaults());
|
||||||
|
params.withHuman(getIndexRequest.humanReadable());
|
||||||
|
params.withMasterTimeout(getIndexRequest.masterNodeTimeout());
|
||||||
|
params.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
static Request getIndex(GetIndexRequest getIndexRequest) {
|
static Request getIndex(GetIndexRequest getIndexRequest) {
|
||||||
String[] indices = getIndexRequest.indices() == null ? Strings.EMPTY_ARRAY : getIndexRequest.indices();
|
String[] indices = getIndexRequest.indices() == null ? Strings.EMPTY_ARRAY : getIndexRequest.indices();
|
||||||
|
|
||||||
|
@ -405,6 +431,28 @@ final class IndicesRequestConverters {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converter for the legacy server-side {@link org.elasticsearch.action.admin.indices.get.GetIndexRequest} that
|
||||||
|
* still supports types
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
static Request indicesExist(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest) {
|
||||||
|
// this can be called with no indices as argument by transport client, not via REST though
|
||||||
|
if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) {
|
||||||
|
throw new IllegalArgumentException("indices are mandatory");
|
||||||
|
}
|
||||||
|
String endpoint = RequestConverters.endpoint(getIndexRequest.indices(), "");
|
||||||
|
Request request = new Request(HttpHead.METHOD_NAME, endpoint);
|
||||||
|
|
||||||
|
RequestConverters.Params params = new RequestConverters.Params(request);
|
||||||
|
params.withLocal(getIndexRequest.local());
|
||||||
|
params.withHuman(getIndexRequest.humanReadable());
|
||||||
|
params.withIndicesOptions(getIndexRequest.indicesOptions());
|
||||||
|
params.withIncludeDefaults(getIndexRequest.includeDefaults());
|
||||||
|
params.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
static Request indicesExist(GetIndexRequest getIndexRequest) {
|
static Request indicesExist(GetIndexRequest getIndexRequest) {
|
||||||
// this can be called with no indices as argument by transport client, not via REST though
|
// this can be called with no indices as argument by transport client, not via REST though
|
||||||
if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) {
|
if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) {
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.client.indices;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
|
import org.elasticsearch.client.TimedRequest;
|
||||||
|
import org.elasticsearch.common.util.ArrayUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to retrieve information about an index.
|
||||||
|
*/
|
||||||
|
public class GetIndexRequest extends TimedRequest {
|
||||||
|
|
||||||
|
public enum Feature {
|
||||||
|
ALIASES,
|
||||||
|
MAPPINGS,
|
||||||
|
SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS };
|
||||||
|
private Feature[] features = DEFAULT_FEATURES;
|
||||||
|
private boolean humanReadable = false;
|
||||||
|
private transient boolean includeDefaults = false;
|
||||||
|
|
||||||
|
private final String[] indices;
|
||||||
|
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true);
|
||||||
|
private boolean local = false;
|
||||||
|
|
||||||
|
public GetIndexRequest(String... indices) {
|
||||||
|
this.indices = indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The indices into which the mappings will be put.
|
||||||
|
*/
|
||||||
|
public String[] indices() {
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndicesOptions indicesOptions() {
|
||||||
|
return indicesOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIndexRequest indicesOptions(IndicesOptions indicesOptions) {
|
||||||
|
this.indicesOptions = indicesOptions;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final GetIndexRequest local(boolean local) {
|
||||||
|
this.local = local;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return local information, do not retrieve the state from master node (default: false).
|
||||||
|
* @return <code>true</code> if local information is to be returned;
|
||||||
|
* <code>false</code> if information is to be retrieved from master node (default).
|
||||||
|
*/
|
||||||
|
public final boolean local() {
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIndexRequest features(Feature... features) {
|
||||||
|
if (features == null) {
|
||||||
|
throw new IllegalArgumentException("features cannot be null");
|
||||||
|
} else {
|
||||||
|
this.features = features;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIndexRequest addFeatures(Feature... features) {
|
||||||
|
if (this.features == DEFAULT_FEATURES) {
|
||||||
|
return features(features);
|
||||||
|
} else {
|
||||||
|
return features(ArrayUtils.concat(features(), features, Feature.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Feature[] features() {
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIndexRequest humanReadable(boolean humanReadable) {
|
||||||
|
this.humanReadable = humanReadable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean humanReadable() {
|
||||||
|
return humanReadable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of "include_defaults".
|
||||||
|
*
|
||||||
|
* @param includeDefaults value of "include_defaults" to be set.
|
||||||
|
* @return this request
|
||||||
|
*/
|
||||||
|
public GetIndexRequest includeDefaults(boolean includeDefaults) {
|
||||||
|
this.includeDefaults = includeDefaults;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to return all default settings for each of the indices.
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if defaults settings for each of the indices need to returned;
|
||||||
|
* <code>false</code> otherwise.
|
||||||
|
*/
|
||||||
|
public boolean includeDefaults() {
|
||||||
|
return includeDefaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.client.indices;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.CollectionUtil;
|
||||||
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||||
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A client side response for a get index action.
|
||||||
|
*/
|
||||||
|
public class GetIndexResponse {
|
||||||
|
|
||||||
|
private Map<String, MappingMetaData> mappings;
|
||||||
|
private Map<String, List<AliasMetaData>> aliases;
|
||||||
|
private Map<String, Settings> settings;
|
||||||
|
private Map<String, Settings> defaultSettings;
|
||||||
|
private String[] indices;
|
||||||
|
|
||||||
|
GetIndexResponse(String[] indices,
|
||||||
|
Map<String, MappingMetaData> mappings,
|
||||||
|
Map<String, List<AliasMetaData>> aliases,
|
||||||
|
Map<String, Settings> settings,
|
||||||
|
Map<String, Settings> defaultSettings) {
|
||||||
|
this.indices = indices;
|
||||||
|
// to have deterministic order
|
||||||
|
Arrays.sort(indices);
|
||||||
|
if (mappings != null) {
|
||||||
|
this.mappings = mappings;
|
||||||
|
}
|
||||||
|
if (aliases != null) {
|
||||||
|
this.aliases = aliases;
|
||||||
|
}
|
||||||
|
if (settings != null) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
if (defaultSettings != null) {
|
||||||
|
this.defaultSettings = defaultSettings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getIndices() {
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, MappingMetaData> getMappings() {
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<AliasMetaData>> getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the originating {@link GetIndexRequest} object was configured to include
|
||||||
|
* defaults, this will contain a mapping of index name to {@link Settings} objects.
|
||||||
|
* The returned {@link Settings} objects will contain only those settings taking
|
||||||
|
* effect as defaults. Any settings explicitly set on the index will be available
|
||||||
|
* via {@link #getSettings()}.
|
||||||
|
* See also {@link GetIndexRequest#includeDefaults(boolean)}
|
||||||
|
*/
|
||||||
|
public Map<String, Settings> getDefaultSettings() {
|
||||||
|
return defaultSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Settings> getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the string value for the specified index and setting. If the includeDefaults flag was not set or set to
|
||||||
|
* false on the {@link GetIndexRequest}, this method will only return a value where the setting was explicitly set
|
||||||
|
* on the index. If the includeDefaults flag was set to true on the {@link GetIndexRequest}, this method will fall
|
||||||
|
* back to return the default value if the setting was not explicitly set.
|
||||||
|
*/
|
||||||
|
public String getSetting(String index, String setting) {
|
||||||
|
Settings indexSettings = settings.get(index);
|
||||||
|
if (setting != null) {
|
||||||
|
if (indexSettings != null && indexSettings.hasValue(setting)) {
|
||||||
|
return indexSettings.get(setting);
|
||||||
|
} else {
|
||||||
|
Settings defaultIndexSettings = defaultSettings.get(index);
|
||||||
|
if (defaultIndexSettings != null) {
|
||||||
|
return defaultIndexSettings.get(setting);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<AliasMetaData> parseAliases(XContentParser parser) throws IOException {
|
||||||
|
List<AliasMetaData> indexAliases = new ArrayList<>();
|
||||||
|
// We start at START_OBJECT since parseIndexEntry ensures that
|
||||||
|
while (parser.nextToken() != Token.END_OBJECT) {
|
||||||
|
ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
|
||||||
|
indexAliases.add(AliasMetaData.Builder.fromXContent(parser));
|
||||||
|
}
|
||||||
|
return indexAliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MappingMetaData parseMappings(XContentParser parser) throws IOException {
|
||||||
|
return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, parser.map());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IndexEntry parseIndexEntry(XContentParser parser) throws IOException {
|
||||||
|
List<AliasMetaData> indexAliases = null;
|
||||||
|
MappingMetaData indexMappings = null;
|
||||||
|
Settings indexSettings = null;
|
||||||
|
Settings indexDefaultSettings = null;
|
||||||
|
// We start at START_OBJECT since fromXContent ensures that
|
||||||
|
while (parser.nextToken() != Token.END_OBJECT) {
|
||||||
|
ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
|
||||||
|
parser.nextToken();
|
||||||
|
if (parser.currentToken() == Token.START_OBJECT) {
|
||||||
|
switch (parser.currentName()) {
|
||||||
|
case "aliases":
|
||||||
|
indexAliases = parseAliases(parser);
|
||||||
|
break;
|
||||||
|
case "mappings":
|
||||||
|
indexMappings = parseMappings(parser);
|
||||||
|
break;
|
||||||
|
case "settings":
|
||||||
|
indexSettings = Settings.fromXContent(parser);
|
||||||
|
break;
|
||||||
|
case "defaults":
|
||||||
|
indexDefaultSettings = Settings.fromXContent(parser);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
parser.skipChildren();
|
||||||
|
}
|
||||||
|
} else if (parser.currentToken() == Token.START_ARRAY) {
|
||||||
|
parser.skipChildren();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new IndexEntry(indexAliases, indexMappings, indexSettings, indexDefaultSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is just an internal container to make stuff easier for returning
|
||||||
|
private static class IndexEntry {
|
||||||
|
List<AliasMetaData> indexAliases = new ArrayList<>();
|
||||||
|
MappingMetaData indexMappings;
|
||||||
|
Settings indexSettings = Settings.EMPTY;
|
||||||
|
Settings indexDefaultSettings = Settings.EMPTY;
|
||||||
|
IndexEntry(List<AliasMetaData> indexAliases, MappingMetaData indexMappings, Settings indexSettings, Settings indexDefaultSettings) {
|
||||||
|
if (indexAliases != null) this.indexAliases = indexAliases;
|
||||||
|
if (indexMappings != null) this.indexMappings = indexMappings;
|
||||||
|
if (indexSettings != null) this.indexSettings = indexSettings;
|
||||||
|
if (indexDefaultSettings != null) this.indexDefaultSettings = indexDefaultSettings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GetIndexResponse fromXContent(XContentParser parser) throws IOException {
|
||||||
|
Map<String, List<AliasMetaData>> aliases = new HashMap<>();
|
||||||
|
Map<String, MappingMetaData> mappings = new HashMap<>();
|
||||||
|
Map<String, Settings> settings = new HashMap<>();
|
||||||
|
Map<String, Settings> defaultSettings = new HashMap<>();
|
||||||
|
List<String> indices = new ArrayList<>();
|
||||||
|
|
||||||
|
if (parser.currentToken() == null) {
|
||||||
|
parser.nextToken();
|
||||||
|
}
|
||||||
|
ensureExpectedToken(Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
|
||||||
|
parser.nextToken();
|
||||||
|
|
||||||
|
while (!parser.isClosed()) {
|
||||||
|
if (parser.currentToken() == Token.START_OBJECT) {
|
||||||
|
// we assume this is an index entry
|
||||||
|
String indexName = parser.currentName();
|
||||||
|
indices.add(indexName);
|
||||||
|
IndexEntry indexEntry = parseIndexEntry(parser);
|
||||||
|
// make the order deterministic
|
||||||
|
CollectionUtil.timSort(indexEntry.indexAliases, Comparator.comparing(AliasMetaData::alias));
|
||||||
|
aliases.put(indexName, Collections.unmodifiableList(indexEntry.indexAliases));
|
||||||
|
mappings.put(indexName, indexEntry.indexMappings);
|
||||||
|
settings.put(indexName, indexEntry.indexSettings);
|
||||||
|
if (indexEntry.indexDefaultSettings.isEmpty() == false) {
|
||||||
|
defaultSettings.put(indexName, indexEntry.indexDefaultSettings);
|
||||||
|
}
|
||||||
|
} else if (parser.currentToken() == Token.START_ARRAY) {
|
||||||
|
parser.skipChildren();
|
||||||
|
} else {
|
||||||
|
parser.nextToken();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new GetIndexResponse(indices.toArray(new String[0]), mappings, aliases, settings, defaultSettings);
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,7 +72,7 @@ public class ClusterRequestConvertersTests extends ESTestCase {
|
||||||
public void testClusterHealth() {
|
public void testClusterHealth() {
|
||||||
ClusterHealthRequest healthRequest = new ClusterHealthRequest();
|
ClusterHealthRequest healthRequest = new ClusterHealthRequest();
|
||||||
Map<String, String> expectedParams = new HashMap<>();
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
RequestConvertersTests.setRandomLocal(healthRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(healthRequest::local, expectedParams);
|
||||||
String timeoutType = ESTestCase.randomFrom("timeout", "masterTimeout", "both", "none");
|
String timeoutType = ESTestCase.randomFrom("timeout", "masterTimeout", "both", "none");
|
||||||
String timeout = ESTestCase.randomTimeValue();
|
String timeout = ESTestCase.randomTimeValue();
|
||||||
String masterTimeout = ESTestCase.randomTimeValue();
|
String masterTimeout = ESTestCase.randomTimeValue();
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.action.DocWriteResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||||
import org.elasticsearch.action.bulk.BulkProcessor;
|
import org.elasticsearch.action.bulk.BulkProcessor;
|
||||||
import org.elasticsearch.action.bulk.BulkRequest;
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
|
@ -48,6 +47,7 @@ import org.elasticsearch.client.core.MultiTermVectorsRequest;
|
||||||
import org.elasticsearch.client.core.MultiTermVectorsResponse;
|
import org.elasticsearch.client.core.MultiTermVectorsResponse;
|
||||||
import org.elasticsearch.client.core.TermVectorsRequest;
|
import org.elasticsearch.client.core.TermVectorsRequest;
|
||||||
import org.elasticsearch.client.core.TermVectorsResponse;
|
import org.elasticsearch.client.core.TermVectorsResponse;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -1231,7 +1231,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
||||||
assertEquals(docId, getResponse.getId());
|
assertEquals(docId, getResponse.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(highLevelClient().indices().exists(new GetIndexRequest().indices(indexPattern, "index"), RequestOptions.DEFAULT));
|
assertTrue(highLevelClient().indices().exists(new GetIndexRequest(indexPattern, "index"), RequestOptions.DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParamsEncode() throws IOException {
|
public void testParamsEncode() throws IOException {
|
||||||
|
|
|
@ -39,8 +39,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
||||||
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
|
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
||||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||||
|
@ -65,10 +63,12 @@ import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||||
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
|
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
|
||||||
import org.elasticsearch.client.indices.GetMappingsRequest;
|
import org.elasticsearch.client.indices.GetMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.GetMappingsResponse;
|
import org.elasticsearch.client.indices.GetMappingsResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
|
|
||||||
import org.elasticsearch.client.indices.IndexTemplateMetaData;
|
import org.elasticsearch.client.indices.IndexTemplateMetaData;
|
||||||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
||||||
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
||||||
|
@ -78,6 +78,7 @@ import org.elasticsearch.client.indices.rollover.RolloverRequest;
|
||||||
import org.elasticsearch.client.indices.rollover.RolloverResponse;
|
import org.elasticsearch.client.indices.rollover.RolloverResponse;
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||||
import org.elasticsearch.common.ValidationException;
|
import org.elasticsearch.common.ValidationException;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
|
@ -96,10 +97,11 @@ import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction;
|
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction;
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction;
|
import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction;
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestGetMappingAction;
|
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestPutMappingAction;
|
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction;
|
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction;
|
||||||
|
import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction;
|
||||||
|
import org.elasticsearch.rest.action.admin.indices.RestGetMappingAction;
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
|
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
|
||||||
|
import org.elasticsearch.rest.action.admin.indices.RestPutMappingAction;
|
||||||
import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction;
|
import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -137,8 +139,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
String indexName = "test_index_exists_index_present";
|
String indexName = "test_index_exists_index_present";
|
||||||
createIndex(indexName, Settings.EMPTY);
|
createIndex(indexName, Settings.EMPTY);
|
||||||
|
|
||||||
GetIndexRequest request = new GetIndexRequest();
|
GetIndexRequest request = new GetIndexRequest(indexName);
|
||||||
request.indices(indexName);
|
|
||||||
|
|
||||||
boolean response = execute(
|
boolean response = execute(
|
||||||
request,
|
request,
|
||||||
|
@ -152,8 +153,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
{
|
{
|
||||||
String indexName = "non_existent_index";
|
String indexName = "non_existent_index";
|
||||||
|
|
||||||
GetIndexRequest request = new GetIndexRequest();
|
GetIndexRequest request = new GetIndexRequest(indexName);
|
||||||
request.indices(indexName);
|
|
||||||
|
|
||||||
boolean response = execute(
|
boolean response = execute(
|
||||||
request,
|
request,
|
||||||
|
@ -170,8 +170,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
|
|
||||||
String nonExistentIndex = "oranges";
|
String nonExistentIndex = "oranges";
|
||||||
|
|
||||||
GetIndexRequest request = new GetIndexRequest();
|
GetIndexRequest request = new GetIndexRequest(existingIndex, nonExistentIndex);
|
||||||
request.indices(existingIndex, nonExistentIndex);
|
|
||||||
|
|
||||||
boolean response = execute(
|
boolean response = execute(
|
||||||
request,
|
request,
|
||||||
|
@ -180,7 +179,20 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
);
|
);
|
||||||
assertFalse(response);
|
assertFalse(response);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIndicesExistsWithTypes() throws IOException {
|
||||||
|
// Index present
|
||||||
|
String indexName = "test_index_exists_index_present";
|
||||||
|
createIndex(indexName, Settings.EMPTY);
|
||||||
|
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexRequest request
|
||||||
|
= new org.elasticsearch.action.admin.indices.get.GetIndexRequest();
|
||||||
|
request.indices(indexName);
|
||||||
|
|
||||||
|
boolean response = execute(request, highLevelClient().indices()::exists, highLevelClient().indices()::existsAsync,
|
||||||
|
expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE));
|
||||||
|
assertTrue(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
@ -416,8 +428,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
|
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
|
||||||
createIndex(indexName, basicSettings, mappings);
|
createIndex(indexName, basicSettings, mappings);
|
||||||
|
|
||||||
GetIndexRequest getIndexRequest = new GetIndexRequest()
|
GetIndexRequest getIndexRequest = new GetIndexRequest(indexName).includeDefaults(false);
|
||||||
.indices(indexName).includeDefaults(false);
|
|
||||||
GetIndexResponse getIndexResponse =
|
GetIndexResponse getIndexResponse =
|
||||||
execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync);
|
execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync);
|
||||||
|
|
||||||
|
@ -426,8 +437,12 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
|
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
|
||||||
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
|
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
|
||||||
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
||||||
assertNotNull(getIndexResponse.getMappings().get(indexName).get("_doc"));
|
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
||||||
Object o = getIndexResponse.getMappings().get(indexName).get("_doc").getSourceAsMap().get("properties");
|
MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName);
|
||||||
|
assertNotNull(mappingMetaData);
|
||||||
|
assertEquals("_doc", mappingMetaData.type());
|
||||||
|
assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetaData.source().string());
|
||||||
|
Object o = mappingMetaData.getSourceAsMap().get("properties");
|
||||||
assertThat(o, instanceOf(Map.class));
|
assertThat(o, instanceOf(Map.class));
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
assertThat(((Map<String, Object>) o).get("field-1"), instanceOf(Map.class));
|
assertThat(((Map<String, Object>) o).get("field-1"), instanceOf(Map.class));
|
||||||
|
@ -436,6 +451,33 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
assertEquals("integer", fieldMapping.get("type"));
|
assertEquals("integer", fieldMapping.get("type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testGetIndexWithTypes() throws IOException {
|
||||||
|
String indexName = "get_index_test";
|
||||||
|
Settings basicSettings = Settings.builder()
|
||||||
|
.put(SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
|
.put(SETTING_NUMBER_OF_REPLICAS, 0)
|
||||||
|
.build();
|
||||||
|
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
|
||||||
|
createIndex(indexName, basicSettings, mappings);
|
||||||
|
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest =
|
||||||
|
new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices(indexName).includeDefaults(false);
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse = execute(getIndexRequest,
|
||||||
|
highLevelClient().indices()::get, highLevelClient().indices()::getAsync,
|
||||||
|
expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE));
|
||||||
|
|
||||||
|
// default settings should be null
|
||||||
|
assertNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
|
||||||
|
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
|
||||||
|
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
|
||||||
|
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
||||||
|
MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName).get("_doc");
|
||||||
|
assertNotNull(mappingMetaData);
|
||||||
|
assertEquals("_doc", mappingMetaData.type());
|
||||||
|
assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetaData.source().string());
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testGetIndexWithDefaults() throws IOException {
|
public void testGetIndexWithDefaults() throws IOException {
|
||||||
String indexName = "get_index_test";
|
String indexName = "get_index_test";
|
||||||
|
@ -446,19 +488,18 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
|
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
|
||||||
createIndex(indexName, basicSettings, mappings);
|
createIndex(indexName, basicSettings, mappings);
|
||||||
|
|
||||||
GetIndexRequest getIndexRequest = new GetIndexRequest()
|
GetIndexRequest getIndexRequest = new GetIndexRequest(indexName).includeDefaults(true);
|
||||||
.indices(indexName).includeDefaults(true);
|
|
||||||
GetIndexResponse getIndexResponse =
|
GetIndexResponse getIndexResponse =
|
||||||
execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync);
|
execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync);
|
||||||
|
|
||||||
assertNotNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
|
assertNotNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
|
||||||
assertEquals(IndexSettings.DEFAULT_REFRESH_INTERVAL,
|
assertEquals(IndexSettings.DEFAULT_REFRESH_INTERVAL,
|
||||||
getIndexResponse.defaultSettings().get(indexName).getAsTime("index.refresh_interval", null));
|
getIndexResponse.getDefaultSettings().get(indexName).getAsTime("index.refresh_interval", null));
|
||||||
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
|
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
|
||||||
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
|
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
|
||||||
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
||||||
assertNotNull(getIndexResponse.getMappings().get(indexName).get("_doc"));
|
assertNotNull(getIndexResponse.getMappings().get(indexName));
|
||||||
Object o = getIndexResponse.getMappings().get(indexName).get("_doc").getSourceAsMap().get("properties");
|
Object o = getIndexResponse.getMappings().get(indexName).getSourceAsMap().get("properties");
|
||||||
assertThat(o, instanceOf(Map.class));
|
assertThat(o, instanceOf(Map.class));
|
||||||
assertThat(((Map<String, Object>) o).get("field-1"), instanceOf(Map.class));
|
assertThat(((Map<String, Object>) o).get("field-1"), instanceOf(Map.class));
|
||||||
Map<String, Object> fieldMapping = (Map<String, Object>) ((Map<String, Object>) o).get("field-1");
|
Map<String, Object> fieldMapping = (Map<String, Object>) ((Map<String, Object>) o).get("field-1");
|
||||||
|
@ -469,7 +510,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
||||||
String nonExistentIndex = "index_that_doesnt_exist";
|
String nonExistentIndex = "index_that_doesnt_exist";
|
||||||
assertFalse(indexExists(nonExistentIndex));
|
assertFalse(indexExists(nonExistentIndex));
|
||||||
|
|
||||||
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(nonExistentIndex);
|
GetIndexRequest getIndexRequest = new GetIndexRequest(nonExistentIndex);
|
||||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||||
() -> execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync));
|
() -> execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync));
|
||||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
|
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
|
||||||
|
@ -48,6 +47,7 @@ import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryReques
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
||||||
import org.elasticsearch.client.indices.GetMappingsRequest;
|
import org.elasticsearch.client.indices.GetMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
||||||
|
@ -104,13 +104,13 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
public void testIndicesExist() {
|
public void testIndicesExist() {
|
||||||
String[] indices = RequestConvertersTests.randomIndicesNames(1, 10);
|
String[] indices = RequestConvertersTests.randomIndicesNames(1, 10);
|
||||||
|
|
||||||
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indices);
|
GetIndexRequest getIndexRequest = new GetIndexRequest(indices);
|
||||||
|
|
||||||
Map<String, String> expectedParams = new HashMap<>();
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
|
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
|
||||||
RequestConvertersTests.setRandomLocal(getIndexRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getIndexRequest::local, expectedParams);
|
||||||
RequestConvertersTests.setRandomHumanReadable(getIndexRequest, expectedParams);
|
RequestConvertersTests.setRandomHumanReadable(getIndexRequest::humanReadable, expectedParams);
|
||||||
RequestConvertersTests.setRandomIncludeDefaults(getIndexRequest, expectedParams);
|
RequestConvertersTests.setRandomIncludeDefaults(getIndexRequest::includeDefaults, expectedParams);
|
||||||
|
|
||||||
final Request request = IndicesRequestConverters.indicesExist(getIndexRequest);
|
final Request request = IndicesRequestConverters.indicesExist(getIndexRequest);
|
||||||
|
|
||||||
|
@ -124,7 +124,35 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
LuceneTestCase.expectThrows(IllegalArgumentException.class, ()
|
LuceneTestCase.expectThrows(IllegalArgumentException.class, ()
|
||||||
-> IndicesRequestConverters.indicesExist(new GetIndexRequest()));
|
-> IndicesRequestConverters.indicesExist(new GetIndexRequest()));
|
||||||
LuceneTestCase.expectThrows(IllegalArgumentException.class, ()
|
LuceneTestCase.expectThrows(IllegalArgumentException.class, ()
|
||||||
-> IndicesRequestConverters.indicesExist(new GetIndexRequest().indices((String[]) null)));
|
-> IndicesRequestConverters.indicesExist(new GetIndexRequest((String[]) null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIndicesExistEmptyIndicesWithTypes() {
|
||||||
|
LuceneTestCase.expectThrows(IllegalArgumentException.class,
|
||||||
|
() -> IndicesRequestConverters.indicesExist(new org.elasticsearch.action.admin.indices.get.GetIndexRequest()));
|
||||||
|
LuceneTestCase.expectThrows(IllegalArgumentException.class, () -> IndicesRequestConverters
|
||||||
|
.indicesExist(new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices((String[]) null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIndicesExistWithTypes() {
|
||||||
|
String[] indices = RequestConvertersTests.randomIndicesNames(1, 10);
|
||||||
|
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest =
|
||||||
|
new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices(indices);
|
||||||
|
|
||||||
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
|
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
|
||||||
|
RequestConvertersTests.setRandomLocal(getIndexRequest::local, expectedParams);
|
||||||
|
RequestConvertersTests.setRandomHumanReadable(getIndexRequest::humanReadable, expectedParams);
|
||||||
|
RequestConvertersTests.setRandomIncludeDefaults(getIndexRequest::includeDefaults, expectedParams);
|
||||||
|
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||||
|
|
||||||
|
final Request request = IndicesRequestConverters.indicesExist(getIndexRequest);
|
||||||
|
|
||||||
|
Assert.assertEquals(HttpHead.METHOD_NAME, request.getMethod());
|
||||||
|
Assert.assertEquals("/" + String.join(",", indices), request.getEndpoint());
|
||||||
|
Assert.assertThat(expectedParams, equalTo(request.getParameters()));
|
||||||
|
Assert.assertNull(request.getEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateIndex() throws IOException {
|
public void testCreateIndex() throws IOException {
|
||||||
|
@ -288,7 +316,7 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
RequestConvertersTests.setRandomIndicesOptions(getMappingRequest::indicesOptions,
|
RequestConvertersTests.setRandomIndicesOptions(getMappingRequest::indicesOptions,
|
||||||
getMappingRequest::indicesOptions, expectedParams);
|
getMappingRequest::indicesOptions, expectedParams);
|
||||||
RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams);
|
RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams);
|
||||||
RequestConvertersTests.setRandomLocal(getMappingRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getMappingRequest::local, expectedParams);
|
||||||
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||||
|
|
||||||
Request request = IndicesRequestConverters.getMappings(getMappingRequest);
|
Request request = IndicesRequestConverters.getMappings(getMappingRequest);
|
||||||
|
@ -436,7 +464,7 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
RequestConvertersTests.setRandomIndicesOptions(getSettingsRequest::indicesOptions, getSettingsRequest::indicesOptions,
|
RequestConvertersTests.setRandomIndicesOptions(getSettingsRequest::indicesOptions, getSettingsRequest::indicesOptions,
|
||||||
expectedParams);
|
expectedParams);
|
||||||
|
|
||||||
RequestConvertersTests.setRandomLocal(getSettingsRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getSettingsRequest::local, expectedParams);
|
||||||
|
|
||||||
if (ESTestCase.randomBoolean()) {
|
if (ESTestCase.randomBoolean()) {
|
||||||
// the request object will not have include_defaults present unless it is set to
|
// the request object will not have include_defaults present unless it is set to
|
||||||
|
@ -477,13 +505,48 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
public void testGetIndex() throws IOException {
|
public void testGetIndex() throws IOException {
|
||||||
String[] indicesUnderTest = ESTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
|
String[] indicesUnderTest = ESTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
|
||||||
|
|
||||||
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indicesUnderTest);
|
GetIndexRequest getIndexRequest = new GetIndexRequest(indicesUnderTest);
|
||||||
|
|
||||||
Map<String, String> expectedParams = new HashMap<>();
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
RequestConvertersTests.setRandomMasterTimeout(getIndexRequest, expectedParams);
|
RequestConvertersTests.setRandomMasterTimeout(getIndexRequest, expectedParams);
|
||||||
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
|
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
|
||||||
RequestConvertersTests.setRandomLocal(getIndexRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getIndexRequest::local, expectedParams);
|
||||||
RequestConvertersTests.setRandomHumanReadable(getIndexRequest, expectedParams);
|
RequestConvertersTests.setRandomHumanReadable(getIndexRequest::humanReadable, expectedParams);
|
||||||
|
|
||||||
|
if (ESTestCase.randomBoolean()) {
|
||||||
|
// the request object will not have include_defaults present unless it is set to
|
||||||
|
// true
|
||||||
|
getIndexRequest.includeDefaults(ESTestCase.randomBoolean());
|
||||||
|
if (getIndexRequest.includeDefaults()) {
|
||||||
|
expectedParams.put("include_defaults", Boolean.toString(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringJoiner endpoint = new StringJoiner("/", "/", "");
|
||||||
|
if (indicesUnderTest != null && indicesUnderTest.length > 0) {
|
||||||
|
endpoint.add(String.join(",", indicesUnderTest));
|
||||||
|
}
|
||||||
|
|
||||||
|
Request request = IndicesRequestConverters.getIndex(getIndexRequest);
|
||||||
|
|
||||||
|
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
|
||||||
|
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
|
||||||
|
Assert.assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
|
||||||
|
Assert.assertThat(request.getEntity(), nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetIndexWithTypes() throws IOException {
|
||||||
|
String[] indicesUnderTest = ESTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
|
||||||
|
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest =
|
||||||
|
new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices(indicesUnderTest);
|
||||||
|
|
||||||
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
|
RequestConvertersTests.setRandomMasterTimeout(getIndexRequest, expectedParams);
|
||||||
|
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
|
||||||
|
RequestConvertersTests.setRandomLocal(getIndexRequest::local, expectedParams);
|
||||||
|
RequestConvertersTests.setRandomHumanReadable(getIndexRequest::humanReadable, expectedParams);
|
||||||
|
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||||
|
|
||||||
if (ESTestCase.randomBoolean()) {
|
if (ESTestCase.randomBoolean()) {
|
||||||
// the request object will not have include_defaults present unless it is set to
|
// the request object will not have include_defaults present unless it is set to
|
||||||
|
@ -734,7 +797,7 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
getAliasesRequest.aliases(aliases);
|
getAliasesRequest.aliases(aliases);
|
||||||
Map<String, String> expectedParams = new HashMap<>();
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
RequestConvertersTests.setRandomLocal(getAliasesRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getAliasesRequest::local, expectedParams);
|
||||||
RequestConvertersTests.setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions,
|
RequestConvertersTests.setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions,
|
||||||
expectedParams);
|
expectedParams);
|
||||||
|
|
||||||
|
@ -910,7 +973,7 @@ public class IndicesRequestConvertersTests extends ESTestCase {
|
||||||
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
|
||||||
|
|
||||||
Map<String, String> expectedParams = new HashMap<>();
|
Map<String, String> expectedParams = new HashMap<>();
|
||||||
RequestConvertersTests.setRandomLocal(getAliasesRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getAliasesRequest::local, expectedParams);
|
||||||
RequestConvertersTests.setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions,
|
RequestConvertersTests.setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions,
|
||||||
expectedParams);
|
expectedParams);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRe
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
||||||
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
|
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.action.bulk.BulkRequest;
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
import org.elasticsearch.action.bulk.BulkShardRequest;
|
import org.elasticsearch.action.bulk.BulkShardRequest;
|
||||||
import org.elasticsearch.action.delete.DeleteRequest;
|
import org.elasticsearch.action.delete.DeleteRequest;
|
||||||
|
@ -50,7 +49,6 @@ import org.elasticsearch.action.support.ActiveShardCount;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.action.support.WriteRequest;
|
import org.elasticsearch.action.support.WriteRequest;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||||
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
|
|
||||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||||
import org.elasticsearch.action.support.replication.ReplicationRequest;
|
import org.elasticsearch.action.support.replication.ReplicationRequest;
|
||||||
import org.elasticsearch.action.update.UpdateRequest;
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
|
@ -1905,20 +1903,20 @@ public class RequestConvertersTests extends ESTestCase {
|
||||||
return indicesOptions;
|
return indicesOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRandomIncludeDefaults(GetIndexRequest request, Map<String, String> expectedParams) {
|
static void setRandomIncludeDefaults(Consumer<Boolean> setter, Map<String, String> expectedParams) {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
boolean includeDefaults = randomBoolean();
|
boolean includeDefaults = randomBoolean();
|
||||||
request.includeDefaults(includeDefaults);
|
setter.accept(includeDefaults);
|
||||||
if (includeDefaults) {
|
if (includeDefaults) {
|
||||||
expectedParams.put("include_defaults", String.valueOf(includeDefaults));
|
expectedParams.put("include_defaults", String.valueOf(includeDefaults));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRandomHumanReadable(GetIndexRequest request, Map<String, String> expectedParams) {
|
static void setRandomHumanReadable(Consumer<Boolean> setter, Map<String, String> expectedParams) {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
boolean humanReadable = randomBoolean();
|
boolean humanReadable = randomBoolean();
|
||||||
request.humanReadable(humanReadable);
|
setter.accept(humanReadable);
|
||||||
if (humanReadable) {
|
if (humanReadable) {
|
||||||
expectedParams.put("human", String.valueOf(humanReadable));
|
expectedParams.put("human", String.valueOf(humanReadable));
|
||||||
}
|
}
|
||||||
|
@ -1935,10 +1933,6 @@ public class RequestConvertersTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRandomLocal(MasterNodeReadRequest<?> request, Map<String, String> expectedParams) {
|
|
||||||
setRandomLocal(request::local, expectedParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setRandomTimeout(TimedRequest request, TimeValue defaultTimeout, Map<String, String> expectedParams) {
|
static void setRandomTimeout(TimedRequest request, TimeValue defaultTimeout, Map<String, String> expectedParams) {
|
||||||
setRandomTimeout(s ->
|
setRandomTimeout(s ->
|
||||||
request.setTimeout(TimeValue.parseTimeValue(s, request.getClass().getName() + ".timeout")),
|
request.setTimeout(TimeValue.parseTimeValue(s, request.getClass().getName() + ".timeout")),
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class SnapshotRequestConvertersTests extends ESTestCase {
|
||||||
|
|
||||||
GetRepositoriesRequest getRepositoriesRequest = new GetRepositoriesRequest();
|
GetRepositoriesRequest getRepositoriesRequest = new GetRepositoriesRequest();
|
||||||
RequestConvertersTests.setRandomMasterTimeout(getRepositoriesRequest, expectedParams);
|
RequestConvertersTests.setRandomMasterTimeout(getRepositoriesRequest, expectedParams);
|
||||||
RequestConvertersTests.setRandomLocal(getRepositoriesRequest, expectedParams);
|
RequestConvertersTests.setRandomLocal(getRepositoriesRequest::local, expectedParams);
|
||||||
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
String[] entries = new String[]{"a", "b", "c"};
|
String[] entries = new String[]{"a", "b", "c"};
|
||||||
|
|
|
@ -38,10 +38,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
||||||
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
|
||||||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
||||||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
|
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
|
||||||
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
|
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
||||||
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
||||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||||
|
@ -69,10 +65,14 @@ import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
|
||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||||
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
import org.elasticsearch.client.indices.FreezeIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
|
||||||
import org.elasticsearch.client.indices.GetMappingsRequest;
|
import org.elasticsearch.client.indices.GetMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.GetMappingsResponse;
|
import org.elasticsearch.client.indices.GetMappingsResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
|
|
||||||
import org.elasticsearch.client.indices.IndexTemplateMetaData;
|
import org.elasticsearch.client.indices.IndexTemplateMetaData;
|
||||||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
||||||
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
||||||
|
@ -82,7 +82,6 @@ import org.elasticsearch.client.indices.rollover.RolloverRequest;
|
||||||
import org.elasticsearch.client.indices.rollover.RolloverResponse;
|
import org.elasticsearch.client.indices.rollover.RolloverResponse;
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||||
|
@ -139,8 +138,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
||||||
|
|
||||||
{
|
{
|
||||||
// tag::indices-exists-request
|
// tag::indices-exists-request
|
||||||
GetIndexRequest request = new GetIndexRequest();
|
GetIndexRequest request = new GetIndexRequest("twitter"); // <1>
|
||||||
request.indices("twitter"); // <1>
|
|
||||||
// end::indices-exists-request
|
// end::indices-exists-request
|
||||||
|
|
||||||
IndicesOptions indicesOptions = IndicesOptions.strictExpand();
|
IndicesOptions indicesOptions = IndicesOptions.strictExpand();
|
||||||
|
@ -167,8 +165,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
GetIndexRequest request = new GetIndexRequest();
|
GetIndexRequest request = new GetIndexRequest("twitter");
|
||||||
request.indices("twitter");
|
|
||||||
|
|
||||||
// tag::indices-exists-execute-listener
|
// tag::indices-exists-execute-listener
|
||||||
ActionListener<Boolean> listener = new ActionListener<Boolean>() {
|
ActionListener<Boolean> listener = new ActionListener<Boolean>() {
|
||||||
|
@ -1230,7 +1227,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
// tag::get-index-request
|
// tag::get-index-request
|
||||||
GetIndexRequest request = new GetIndexRequest().indices("index"); // <1>
|
GetIndexRequest request = new GetIndexRequest("index"); // <1>
|
||||||
// end::get-index-request
|
// end::get-index-request
|
||||||
|
|
||||||
// tag::get-index-request-indicesOptions
|
// tag::get-index-request-indicesOptions
|
||||||
|
@ -1246,13 +1243,13 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
||||||
// end::get-index-execute
|
// end::get-index-execute
|
||||||
|
|
||||||
// tag::get-index-response
|
// tag::get-index-response
|
||||||
ImmutableOpenMap<String, MappingMetaData> indexMappings = getIndexResponse.getMappings().get("index"); // <1>
|
MappingMetaData indexMappings = getIndexResponse.getMappings().get("index"); // <1>
|
||||||
Map<String, Object> indexTypeMappings = indexMappings.get("_doc").getSourceAsMap(); // <2>
|
Map<String, Object> indexTypeMappings = indexMappings.getSourceAsMap(); // <2>
|
||||||
List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get("index"); // <3>
|
List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get("index"); // <3>
|
||||||
String numberOfShardsString = getIndexResponse.getSetting("index", "index.number_of_shards"); // <4>
|
String numberOfShardsString = getIndexResponse.getSetting("index", "index.number_of_shards"); // <4>
|
||||||
Settings indexSettings = getIndexResponse.getSettings().get("index"); // <5>
|
Settings indexSettings = getIndexResponse.getSettings().get("index"); // <5>
|
||||||
Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null); // <6>
|
Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null); // <6>
|
||||||
TimeValue time = getIndexResponse.defaultSettings().get("index")
|
TimeValue time = getIndexResponse.getDefaultSettings().get("index")
|
||||||
.getAsTime("index.refresh_interval", null); // <7>
|
.getAsTime("index.refresh_interval", null); // <7>
|
||||||
// end::get-index-response
|
// end::get-index-response
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.client.indices;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
|
import org.elasticsearch.client.indices.GetIndexRequest.Feature;
|
||||||
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
|
||||||
|
public class GetIndexRequestTests extends ESTestCase {
|
||||||
|
|
||||||
|
public void testIndices() {
|
||||||
|
String[] indices = generateRandomStringArray(5, 5, false, true);
|
||||||
|
GetIndexRequest request = new GetIndexRequest(indices);
|
||||||
|
assertArrayEquals(indices, request.indices());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFeatures() {
|
||||||
|
int numFeature = randomIntBetween(0, 3);
|
||||||
|
Feature[] features = new Feature[numFeature];
|
||||||
|
for (int i = 0; i < numFeature; i++) {
|
||||||
|
features[i] = randomFrom(GetIndexRequest.DEFAULT_FEATURES);
|
||||||
|
}
|
||||||
|
GetIndexRequest request = new GetIndexRequest().addFeatures(features);
|
||||||
|
assertArrayEquals(features, request.features());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLocal() {
|
||||||
|
boolean local = randomBoolean();
|
||||||
|
GetIndexRequest request = new GetIndexRequest().local(local);
|
||||||
|
assertEquals(local, request.local());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHumanReadable() {
|
||||||
|
boolean humanReadable = randomBoolean();
|
||||||
|
GetIndexRequest request = new GetIndexRequest().humanReadable(humanReadable);
|
||||||
|
assertEquals(humanReadable, request.humanReadable());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIncludeDefaults() {
|
||||||
|
boolean includeDefaults = randomBoolean();
|
||||||
|
GetIndexRequest request = new GetIndexRequest().includeDefaults(includeDefaults);
|
||||||
|
assertEquals(includeDefaults, request.includeDefaults());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIndicesOptions() {
|
||||||
|
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
|
||||||
|
GetIndexRequest request = new GetIndexRequest().indicesOptions(indicesOptions);
|
||||||
|
assertEquals(indicesOptions, request.indicesOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,195 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.client.indices;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.CollectionUtil;
|
||||||
|
import org.elasticsearch.client.GetAliasesResponseTests;
|
||||||
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||||
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||||
|
import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
|
import org.elasticsearch.common.xcontent.ToXContent.Params;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.index.RandomCreateIndexGenerator;
|
||||||
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
|
||||||
|
|
||||||
|
public class GetIndexResponseTests extends ESTestCase {
|
||||||
|
|
||||||
|
// Because the client-side class does not have a toXContent method, we test xContent serialization by creating
|
||||||
|
// a random client object, converting it to a server object then serializing it to xContent, and finally
|
||||||
|
// parsing it back as a client object. We check equality between the original client object, and the parsed one.
|
||||||
|
public void testFromXContent() throws IOException {
|
||||||
|
xContentTester(
|
||||||
|
this::createParser,
|
||||||
|
GetIndexResponseTests::createTestInstance,
|
||||||
|
GetIndexResponseTests::toXContent,
|
||||||
|
GetIndexResponse::fromXContent)
|
||||||
|
.supportsUnknownFields(false)
|
||||||
|
.assertToXContentEquivalence(false)
|
||||||
|
.assertEqualsConsumer(GetIndexResponseTests::assertEqualInstances)
|
||||||
|
.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertEqualInstances(GetIndexResponse expected, GetIndexResponse actual) {
|
||||||
|
assertArrayEquals(expected.getIndices(), actual.getIndices());
|
||||||
|
assertEquals(expected.getMappings(), actual.getMappings());
|
||||||
|
assertEquals(expected.getSettings(), actual.getSettings());
|
||||||
|
assertEquals(expected.getDefaultSettings(), actual.getDefaultSettings());
|
||||||
|
assertEquals(expected.getAliases(), actual.getAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GetIndexResponse createTestInstance() {
|
||||||
|
String[] indices = generateRandomStringArray(5, 5, false, false);
|
||||||
|
Map<String, MappingMetaData> mappings = new HashMap<>();
|
||||||
|
Map<String, List<AliasMetaData>> aliases = new HashMap<>();
|
||||||
|
Map<String, Settings> settings = new HashMap<>();
|
||||||
|
Map<String, Settings> defaultSettings = new HashMap<>();
|
||||||
|
IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS;
|
||||||
|
boolean includeDefaults = randomBoolean();
|
||||||
|
for (String index: indices) {
|
||||||
|
mappings.put(index, createMappingsForIndex());
|
||||||
|
|
||||||
|
List<AliasMetaData> aliasMetaDataList = new ArrayList<>();
|
||||||
|
int aliasesNum = randomIntBetween(0, 3);
|
||||||
|
for (int i=0; i<aliasesNum; i++) {
|
||||||
|
aliasMetaDataList.add(GetAliasesResponseTests.createAliasMetaData());
|
||||||
|
}
|
||||||
|
CollectionUtil.timSort(aliasMetaDataList, Comparator.comparing(AliasMetaData::alias));
|
||||||
|
aliases.put(index, Collections.unmodifiableList(aliasMetaDataList));
|
||||||
|
|
||||||
|
Settings.Builder builder = Settings.builder();
|
||||||
|
builder.put(RandomCreateIndexGenerator.randomIndexSettings());
|
||||||
|
settings.put(index, builder.build());
|
||||||
|
|
||||||
|
if (includeDefaults) {
|
||||||
|
defaultSettings.put(index, indexScopedSettings.diff(settings.get(index), Settings.EMPTY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new GetIndexResponse(indices, mappings, aliases, settings, defaultSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MappingMetaData createMappingsForIndex() {
|
||||||
|
int typeCount = rarely() ? 0 : 1;
|
||||||
|
MappingMetaData mmd;
|
||||||
|
try {
|
||||||
|
mmd = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, Collections.emptyMap());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < typeCount; i++) {
|
||||||
|
if (rarely() == false) { // rarely have no fields
|
||||||
|
Map<String, Object> mappings = new HashMap<>();
|
||||||
|
mappings.put("field-" + i, randomFieldMapping());
|
||||||
|
if (randomBoolean()) {
|
||||||
|
mappings.put("field2-" + i, randomFieldMapping());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String typeName = MapperService.SINGLE_MAPPING_NAME;
|
||||||
|
mmd = new MappingMetaData(typeName, mappings);
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail("shouldn't have failed " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not meant to be exhaustive
|
||||||
|
private static Map<String, Object> randomFieldMapping() {
|
||||||
|
Map<String, Object> mappings = new HashMap<>();
|
||||||
|
if (randomBoolean()) {
|
||||||
|
mappings.put("type", randomBoolean() ? "text" : "keyword");
|
||||||
|
mappings.put("index", "analyzed");
|
||||||
|
mappings.put("analyzer", "english");
|
||||||
|
} else if (randomBoolean()) {
|
||||||
|
mappings.put("type", randomFrom("integer", "float", "long", "double"));
|
||||||
|
mappings.put("index", Objects.toString(randomBoolean()));
|
||||||
|
} else if (randomBoolean()) {
|
||||||
|
mappings.put("type", "object");
|
||||||
|
mappings.put("dynamic", "strict");
|
||||||
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
Map<String, Object> props1 = new HashMap<>();
|
||||||
|
props1.put("type", randomFrom("text", "keyword"));
|
||||||
|
props1.put("analyzer", "keyword");
|
||||||
|
properties.put("subtext", props1);
|
||||||
|
Map<String, Object> props2 = new HashMap<>();
|
||||||
|
props2.put("type", "object");
|
||||||
|
Map<String, Object> prop2properties = new HashMap<>();
|
||||||
|
Map<String, Object> props3 = new HashMap<>();
|
||||||
|
props3.put("type", "integer");
|
||||||
|
props3.put("index", "false");
|
||||||
|
prop2properties.put("subsubfield", props3);
|
||||||
|
props2.put("properties", prop2properties);
|
||||||
|
mappings.put("properties", properties);
|
||||||
|
} else {
|
||||||
|
mappings.put("type", "keyword");
|
||||||
|
}
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void toXContent(GetIndexResponse response, XContentBuilder builder) throws IOException {
|
||||||
|
// first we need to repackage from GetIndexResponse to org.elasticsearch.action.admin.indices.get.GetIndexResponse
|
||||||
|
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> allMappings = ImmutableOpenMap.builder();
|
||||||
|
ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliases = ImmutableOpenMap.builder();
|
||||||
|
ImmutableOpenMap.Builder<String, Settings> settings = ImmutableOpenMap.builder();
|
||||||
|
ImmutableOpenMap.Builder<String, Settings> defaultSettings = ImmutableOpenMap.builder();
|
||||||
|
|
||||||
|
Map<String, MappingMetaData> indexMappings = response.getMappings();
|
||||||
|
for (String index : response.getIndices()) {
|
||||||
|
MappingMetaData mmd = indexMappings.get(index);
|
||||||
|
ImmutableOpenMap.Builder<String, MappingMetaData> typedMappings = ImmutableOpenMap.builder();
|
||||||
|
if (mmd != null) {
|
||||||
|
typedMappings.put(MapperService.SINGLE_MAPPING_NAME, mmd);
|
||||||
|
}
|
||||||
|
allMappings.put(index, typedMappings.build());
|
||||||
|
aliases.put(index, response.getAliases().get(index));
|
||||||
|
settings.put(index, response.getSettings().get(index));
|
||||||
|
defaultSettings.put(index, response.getDefaultSettings().get(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
org.elasticsearch.action.admin.indices.get.GetIndexResponse serverResponse
|
||||||
|
= new org.elasticsearch.action.admin.indices.get.GetIndexResponse(
|
||||||
|
response.getIndices(),
|
||||||
|
allMappings.build(),
|
||||||
|
aliases.build(),
|
||||||
|
settings.build(),
|
||||||
|
defaultSettings.build());
|
||||||
|
|
||||||
|
// then we can call its toXContent method, forcing no output of types
|
||||||
|
Params params = new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "false"));
|
||||||
|
serverResponse.toXContent(builder, params);
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,7 +43,6 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
||||||
|
@ -61,7 +60,7 @@ public class GetIndexResponse extends ActionResponse implements ToXContentObject
|
||||||
private ImmutableOpenMap<String, Settings> defaultSettings = ImmutableOpenMap.of();
|
private ImmutableOpenMap<String, Settings> defaultSettings = ImmutableOpenMap.of();
|
||||||
private String[] indices;
|
private String[] indices;
|
||||||
|
|
||||||
GetIndexResponse(String[] indices,
|
public GetIndexResponse(String[] indices,
|
||||||
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings,
|
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings,
|
||||||
ImmutableOpenMap<String, List<AliasMetaData>> aliases,
|
ImmutableOpenMap<String, List<AliasMetaData>> aliases,
|
||||||
ImmutableOpenMap<String, Settings> settings,
|
ImmutableOpenMap<String, Settings> settings,
|
||||||
|
@ -315,9 +314,16 @@ public class GetIndexResponse extends ActionResponse implements ToXContentObject
|
||||||
|
|
||||||
private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException {
|
private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException {
|
||||||
ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder();
|
ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder();
|
||||||
Map<String, Object> map = parser.map();
|
// We start at START_OBJECT since parseIndexEntry ensures that
|
||||||
if (map.isEmpty() == false) {
|
while (parser.nextToken() != Token.END_OBJECT) {
|
||||||
indexMappings.put(MapperService.SINGLE_MAPPING_NAME, new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, map));
|
ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
|
||||||
|
parser.nextToken();
|
||||||
|
if (parser.currentToken() == Token.START_OBJECT) {
|
||||||
|
String mappingType = parser.currentName();
|
||||||
|
indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map()));
|
||||||
|
} else if (parser.currentToken() == Token.START_ARRAY) {
|
||||||
|
parser.skipChildren();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return indexMappings.build();
|
return indexMappings.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
||||||
public class RestGetIndicesAction extends BaseRestHandler {
|
public class RestGetIndicesAction extends BaseRestHandler {
|
||||||
|
|
||||||
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetIndicesAction.class));
|
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetIndicesAction.class));
|
||||||
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using `include_type_name` in get indices requests is deprecated. "
|
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using `include_type_name` in get indices requests"
|
||||||
+ "The parameter will be removed in the next major version.";
|
+ " is deprecated. The parameter will be removed in the next major version.";
|
||||||
|
|
||||||
private static final Set<String> allowedResponseParameters = Collections
|
private static final Set<String> allowedResponseParameters = Collections
|
||||||
.unmodifiableSet(Stream.concat(Collections.singleton(INCLUDE_TYPE_NAME_PARAMETER).stream(), Settings.FORMAT_PARAMS.stream())
|
.unmodifiableSet(Stream.concat(Collections.singleton(INCLUDE_TYPE_NAME_PARAMETER).stream(), Settings.FORMAT_PARAMS.stream())
|
||||||
|
|
|
@ -31,9 +31,10 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.settings.IndexScopedSettings;
|
import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.index.RandomCreateIndexGenerator;
|
import org.elasticsearch.index.RandomCreateIndexGenerator;
|
||||||
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
|
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
@ -73,10 +74,6 @@ public class GetIndexResponseTests extends AbstractStreamableXContentTestCase<Ge
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GetIndexResponse createTestInstance() {
|
protected GetIndexResponse createTestInstance() {
|
||||||
return createTestInstance(randomBoolean());
|
|
||||||
}
|
|
||||||
|
|
||||||
private GetIndexResponse createTestInstance(boolean randomTypeName) {
|
|
||||||
String[] indices = generateRandomStringArray(5, 5, false, false);
|
String[] indices = generateRandomStringArray(5, 5, false, false);
|
||||||
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.builder();
|
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.builder();
|
||||||
ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliases = ImmutableOpenMap.builder();
|
ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliases = ImmutableOpenMap.builder();
|
||||||
|
@ -87,7 +84,7 @@ public class GetIndexResponseTests extends AbstractStreamableXContentTestCase<Ge
|
||||||
for (String index: indices) {
|
for (String index: indices) {
|
||||||
// rarely have no types
|
// rarely have no types
|
||||||
int typeCount = rarely() ? 0 : 1;
|
int typeCount = rarely() ? 0 : 1;
|
||||||
mappings.put(index, GetMappingsResponseTests.createMappingsForIndex(typeCount, randomTypeName));
|
mappings.put(index, GetMappingsResponseTests.createMappingsForIndex(typeCount, true));
|
||||||
|
|
||||||
List<AliasMetaData> aliasMetaDataList = new ArrayList<>();
|
List<AliasMetaData> aliasMetaDataList = new ArrayList<>();
|
||||||
int aliasesNum = randomIntBetween(0, 3);
|
int aliasesNum = randomIntBetween(0, 3);
|
||||||
|
@ -110,12 +107,6 @@ public class GetIndexResponseTests extends AbstractStreamableXContentTestCase<Ge
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected GetIndexResponse createXContextTestInstance(XContentType xContentType) {
|
|
||||||
// don't use random type names for XContent roundtrip tests because we cannot parse them back anymore
|
|
||||||
return createTestInstance(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||||
//we do not want to add new fields at the root (index-level), or inside the blocks
|
//we do not want to add new fields at the root (index-level), or inside the blocks
|
||||||
|
@ -203,4 +194,13 @@ public class GetIndexResponseTests extends AbstractStreamableXContentTestCase<Ge
|
||||||
|
|
||||||
Assert.assertEquals(TEST_6_3_0_RESPONSE_BYTES, base64OfResponse);
|
Assert.assertEquals(TEST_6_3_0_RESPONSE_BYTES, base64OfResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For xContent roundtrip testing we force the xContent output to still contain types because the parser still expects them.
|
||||||
|
* The new typeless parsing is implemented in the client side GetIndexResponse.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected ToXContent.Params getToXContentParams() {
|
||||||
|
return new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "true"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue