Introduce an `include_type_name` constant (#37155)

I started referring to this parameter name from various places in #37149 so I
think it's a good idea to simplify things by referring to a common constant.
This commit is contained in:
Christoph Büscher 2019-01-07 10:41:40 +01:00 committed by GitHub
parent 12a105e5ef
commit d18c3d651d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -58,6 +58,12 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH
private final LongAdder usageCount = new LongAdder();
/**
* Parameter that controls whether certain REST apis should include type names in their requests or responses.
* Note: Support for this parameter will be removed after the transition perido to typeless APIs.
*/
protected static final String INCLUDE_TYPE_NAME_PARAMETER = "include_type_name";
protected BaseRestHandler(Settings settings) {
// TODO drop settings from ctor
}

View File

@ -49,7 +49,7 @@ public class RestCreateIndexAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final boolean includeTypeName = request.paramAsBoolean("include_type_name", true);
final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, true);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
if (request.hasContent()) {
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.content(), false, request.getXContentType()).v2();

View File

@ -20,8 +20,9 @@
package org.elasticsearch.rest.action.admin.indices;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.support.IndicesOptions;
@ -85,7 +86,7 @@ public class RestGetMappingAction extends BaseRestHandler {
deprecationLogger.deprecated("Type exists requests are deprecated, as types have been deprecated.");
}
final boolean includeTypeName = request.paramAsBoolean("include_type_name", true);
final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, true);
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest();

View File

@ -68,7 +68,7 @@ public class RestPutMappingAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final boolean includeTypeName = request.paramAsBoolean("include_type_name", true);
final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, true);
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
final String type = request.param("type");
if (type != null && includeTypeName == false) {