Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types removal - add constants for include_type_names #37304

Merged
merged 1 commit into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
Expand Down Expand Up @@ -1033,13 +1034,13 @@ public void testIncludeTypeNameOnMultiTypesIndices() throws IOException {
} else {
// GET mappings
Request getMappingsRequest = new Request("GET", index + "/_mappings");
getMappingsRequest.addParameter("include_type_name", "false");
getMappingsRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "false");
ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(getMappingsRequest));
assertThat(EntityUtils.toString(ex.getResponse().getEntity()), Matchers.containsString("has multiple mappings"));

// PUT mappings
Request putMappingsRequest = new Request("PUT", index + "/_mappings");
putMappingsRequest.addParameter("include_type_name", "false");
putMappingsRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "false");
String mapping = Strings.toString(JsonXContent.contentBuilder()
.startObject()
.startObject("properties")
Expand Down Expand Up @@ -1079,7 +1080,7 @@ public void testIncludeTypeNameOnSingleTypeIndices() throws IOException {
} else {
// PUT mappings
Request putMappingsRequest = new Request("PUT", index + "/_mappings");
putMappingsRequest.addParameter("include_type_name", "false");
putMappingsRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "false");
String mapping = Strings.toString(JsonXContent.contentBuilder()
.startObject()
.startObject("properties")
Expand All @@ -1093,7 +1094,7 @@ public void testIncludeTypeNameOnSingleTypeIndices() throws IOException {

// GET mappings
Request getMappingsRequest = new Request("GET", index + "/_mappings");
getMappingsRequest.addParameter("include_type_name", "false");
getMappingsRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "false");
if (getOldClusterVersion().before(Version.V_6_0_0)) {
ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(getMappingsRequest));
assertThat(EntityUtils.toString(ex.getResponse().getEntity()), Matchers.containsString("has multiple mappings"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;

public class GetMappingsResponse extends ActionResponse implements ToXContentFragment {

Expand Down Expand Up @@ -132,7 +133,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params, boolea
for (final ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
if (typeEntry.key.equals("_default_") == false) {
if (mappings != null) {
throw new IllegalArgumentException("Cannot use [include_type_name=false] on index [" + indexEntry.key +
throw new IllegalArgumentException("Cannot use ["+
INCLUDE_TYPE_NAME_PARAMETER +"=false] on index [" + indexEntry.key +
"] that has multiple mappings: " + indexEntry.value.keys());
}
mappings = typeEntry.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ 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 period to typeless APIs.
*/
public static final String INCLUDE_TYPE_NAME_PARAMETER = "include_type_name";
public static final boolean DEFAULT_INCLUDE_TYPE_NAME_POLICY = true;

protected BaseRestHandler(Settings settings) {
// TODO drop settings from ctor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String getName() {

@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, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
if (request.hasContent()) {
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.content(), false, request.getXContentType()).v2();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String getName() {

@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, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getName() {

@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, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
final String type = request.param("type");
if (type != null && includeTypeName == false) {
Expand Down