Skip to content

Mappings get put and get mappings #58426

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

Merged
merged 80 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
96ebb5c
init work. 221 vs 231 failing
pgomulka Mar 25, 2020
2e922bf
allow registering multiple rest actions under the same path
pgomulka Mar 27, 2020
e7eda97
revert out dirs
pgomulka Mar 27, 2020
5dac4b9
Merge branch 'compat_rest_api' into compat/create_index_include_type
pgomulka Mar 27, 2020
a213e6c
extend restcreateindexaction
pgomulka Mar 27, 2020
f1ad677
code style and discovery nodes in indexaction
pgomulka Mar 27, 2020
8ff3463
fix double registration
pgomulka Mar 30, 2020
9b8a26a
add search action v7
pgomulka Mar 30, 2020
b0a12bd
search & multisearch
pgomulka Mar 31, 2020
b94be5c
types with consumer
pgomulka Apr 1, 2020
f78e021
cleanup type funciton
pgomulka Apr 1, 2020
9eb1c68
packages fixed
pgomulka Apr 1, 2020
a421d56
update by query, delete by query, multi term and term
pgomulka Apr 1, 2020
3364141
package rename
pgomulka Apr 1, 2020
8abcc0a
spotless
pgomulka Apr 1, 2020
6efdb30
checkstyle
pgomulka Apr 1, 2020
90c37e2
fake request build iwth compat
pgomulka Apr 1, 2020
484e4ac
fixing some tests
pgomulka Apr 1, 2020
6184a9d
term vector body not finished
pgomulka Apr 2, 2020
1ee4487
additional testing and using version
pgomulka Apr 2, 2020
abe1d28
unused method
pgomulka Apr 2, 2020
d8fc2e5
method handlers - returning null when no handler under a method was r…
pgomulka Apr 2, 2020
d998555
comments
pgomulka Apr 3, 2020
ec8df43
remove unused constant
pgomulka Apr 3, 2020
8602f65
Merge branch 'compat_rest_api' into compat/create_index_include_type
pgomulka Apr 20, 2020
f3d25e0
fix javadoc
pgomulka Apr 20, 2020
7024913
compile
pgomulka Apr 20, 2020
446c114
Merge branch 'compat/create_index_include_type' into compat/search
pgomulka Apr 20, 2020
cafee2f
spotless
pgomulka Apr 20, 2020
f52dbc1
spotless
pgomulka Apr 20, 2020
0b07539
Merge branch 'compat_rest_api' into compat/create_index_include_type
pgomulka Apr 21, 2020
07a5dbc
Merge branch 'compat/create_index_include_type' into compat/search
pgomulka Apr 21, 2020
8135794
v7 name
pgomulka Apr 22, 2020
2087c6a
Merge branch 'compat/create_index_include_type' into compat/search
pgomulka Apr 22, 2020
7e7ed63
versions and names
pgomulka Apr 22, 2020
81a62fe
spotless
pgomulka Apr 22, 2020
d65a4a2
import fix
pgomulka Apr 22, 2020
adb1a1e
fix tests
pgomulka Apr 22, 2020
f819313
fix test
pgomulka Apr 22, 2020
6e28d24
javadoc
pgomulka Apr 22, 2020
a77716e
Merge branch 'compat_rest_api' into compat/create_index_include_type
pgomulka Apr 23, 2020
dcf588c
Merge branch 'compat/create_index_include_type' into compat/search
pgomulka Apr 23, 2020
da0edd7
Merge branch 'compat_rest_api' into compat/search
pgomulka Apr 28, 2020
42b40ec
fix merge problem
pgomulka Apr 29, 2020
8912c60
Merge branch 'compat_rest_api' into compat/search
pgomulka Apr 29, 2020
6c67db3
Merge branch 'compat_rest_api' into compat/search
pgomulka Apr 29, 2020
5a720c5
Merge branch 'compat_rest_api' into compat/search
pgomulka Jun 17, 2020
5f3158c
compile fix for deprecate method rename
pgomulka Jun 17, 2020
0249a8d
Compatible Delete and Update rest actions
pgomulka Jun 17, 2020
69f408b
checkstyle
pgomulka Jun 17, 2020
cb97b5d
not working, but some fixed
pgomulka Jun 17, 2020
2d5274f
validate handlers version
pgomulka Jun 18, 2020
63f524c
Merge branch 'compat/delete_update' into compat/mapping
pgomulka Jun 18, 2020
c645bfb
157 passing of 1308 tests.
pgomulka Jun 23, 2020
e8b28d6
Merge branch 'compat_rest_api' into compat/search
pgomulka Jul 7, 2020
ff3b016
Merge branch 'compat/search' into compat/mapping
pgomulka Jul 7, 2020
83afde4
fix after merge master
pgomulka Jul 7, 2020
4a6e796
spotless
pgomulka Jul 7, 2020
660f086
spotless
pgomulka Jul 7, 2020
85d837f
implementation
pgomulka Jul 7, 2020
7e1ab7f
Merge branch 'compat_rest_api' into compat/delete_update
pgomulka Jul 7, 2020
9c3031f
Merge branch 'compat/search' into compat/delete_update
pgomulka Jul 7, 2020
188bab2
checkstyle
pgomulka Jul 7, 2020
4d8cb1f
Merge branch 'compat/delete_update' into compat/mapping
pgomulka Jul 7, 2020
f070e03
fix tests
pgomulka Jul 7, 2020
9f382e2
Merge branch 'compat/delete_update' into compat/mapping
pgomulka Jul 7, 2020
7bad475
cleanup
pgomulka Jul 7, 2020
bab4d96
Merge branch 'compat/delete_update' into compat/mapping
pgomulka Jul 7, 2020
d08f0f9
checkstyle
pgomulka Jul 7, 2020
1f04044
Merge branch 'compat_rest_api' into compat/search
pgomulka Jul 8, 2020
8595c33
Merge branch 'compat/search' into compat/delete_update
pgomulka Jul 8, 2020
e302959
Merge branch 'compat/delete_update' into compat/mapping
pgomulka Jul 8, 2020
eb0b358
test overrides
pgomulka Jul 8, 2020
24a44a8
Merge branch 'compat_rest_api' into compat/search
pgomulka Jul 8, 2020
25788ff
Merge branch 'compat/search' into compat/delete_update
pgomulka Jul 8, 2020
0db1e03
Merge branch 'compat/delete_update' into compat/mapping
pgomulka Jul 8, 2020
bb50b62
fix get mappings
pgomulka Jul 8, 2020
2b1f503
put overrides
pgomulka Jul 13, 2020
699bfac
Merge branch 'compat_rest_api' into compat/mapping
pgomulka Jul 14, 2020
2fa8953
spotless
pgomulka Jul 14, 2020
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 @@ -42,6 +42,7 @@ public class RestCreateIndexActionV7 extends RestCreateIndexAction {
* Parameter that controls whether certain REST apis should include type names in their requests.
*/
public static final String INCLUDE_TYPE_NAME_PARAMETER = "include_type_name";
public static final boolean DEFAULT_INCLUDE_TYPE_NAME_POLICY = false;

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.rest.action.admin.indices;

import org.elasticsearch.Version;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.RestRequest;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.rest.RestRequest.Method.GET;

public class RestGetFieldMappingActionV7 extends RestGetFieldMappingAction {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetFieldMappingActionV7.class);
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in get "
+ "field mapping requests is deprecated. The parameter will be removed in the next major version.";

@Override
public List<Route> routes() {
return List.of(
new Route(GET, "/_mapping/field/{fields}"),
new Route(GET, "/{index}/_mapping/field/{fields}"),

new Route(GET, "/_mapping/{type}/field/{fields}"),
new Route(GET, "/{index}/{type}/_mapping/field/{fields}"),
new Route(GET, "/{index}/_mapping/{type}/field/{fields}")
);
}

@Override
public String getName() {
return "get_field_mapping_action_v7";
}

@Override
public Version compatibleWithVersion() {
return Version.V_7_0_0;
}

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");

boolean includeTypeName = request.paramAsBoolean(
RestCreateIndexActionV7.INCLUDE_TYPE_NAME_PARAMETER,
RestCreateIndexActionV7.DEFAULT_INCLUDE_TYPE_NAME_POLICY
);
if (includeTypeName == false && types.length > 0) {
throw new IllegalArgumentException("Types cannot be specified unless include_type_name" + " is set to true.");
}
if (request.hasParam(RestCreateIndexActionV7.INCLUDE_TYPE_NAME_PARAMETER)) {
request.param(RestCreateIndexActionV7.INCLUDE_TYPE_NAME_PARAMETER);
deprecationLogger.deprecate("get_field_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
// todo compatible log about using INCLUDE_TYPE_NAME_PARAMETER
}
if (types.length > 0) {
// todo compatible log about using types in path
}
if (request.hasParam("local")) {
request.param("local");
deprecationLogger.deprecate(
"get_field_mapping_local",
"Use [local] in get field mapping requests is deprecated. " + "The parameter will be removed in the next major version"
);
}
return super.prepareRequest(request, client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.rest.action.admin.indices;

import org.elasticsearch.Version;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.RestRequest;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
import static org.elasticsearch.rest.action.admin.indices.RestCreateIndexActionV7.DEFAULT_INCLUDE_TYPE_NAME_POLICY;
import static org.elasticsearch.rest.action.admin.indices.RestCreateIndexActionV7.INCLUDE_TYPE_NAME_PARAMETER;

public class RestGetMappingActionV7 extends RestGetMappingAction {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetMappingActionV7.class);
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in get"
+ " mapping requests is deprecated. The parameter will be removed in the next major version.";

@Override
public List<Route> routes() {
return List.of(
new Route(GET, "/{index}/{type}/_mapping"),
new Route(GET, "/{index}/_mappings/{type}"),
new Route(GET, "/{index}/_mapping/{type}"),
new Route(HEAD, "/{index}/_mapping/{type}"),
new Route(GET, "/_mapping/{type}"),
new Route(GET, "/_mapping"),
new Route(GET, "/_mappings"),
new Route(GET, "/{index}/_mapping"),
new Route(GET, "/{index}/_mappings")
);
}

@Override
public String getName() {
return "get_mapping_action_v7";
}

@Override
public Version compatibleWithVersion() {
return Version.V_7_0_0;
}

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);

if (request.method().equals(HEAD)) {
deprecationLogger.deprecate("get_mapping_with_types", "Type exists requests are deprecated, as types have been deprecated.");
} else if (includeTypeName == false && types.length > 0) {
throw new IllegalArgumentException(
"Types cannot be provided in get mapping requests, unless" + " include_type_name is set to true."
);
}
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
deprecationLogger.deprecate("get_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
}
if (types.length > 0) {
// todo compatible log about using types in path
}
return super.prepareRequest(request, client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.rest.action.admin.indices;

import org.elasticsearch.Version;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.RestRequest;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
import static org.elasticsearch.rest.action.admin.indices.RestCreateIndexActionV7.DEFAULT_INCLUDE_TYPE_NAME_POLICY;
import static org.elasticsearch.rest.action.admin.indices.RestCreateIndexActionV7.INCLUDE_TYPE_NAME_PARAMETER;

public class RestPutMappingActionV7 extends RestPutMappingAction {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestPutMappingActionV7.class);
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using include_type_name in put "
+ "mapping requests is deprecated. The parameter will be removed in the next major version.";

@Override
public List<Route> routes() {
return List.of(
new Route(PUT, "/{index}/{type}/_mapping"),
new Route(PUT, "/{index}/_mapping/{type}"),
new Route(PUT, "/_mapping/{type}"),

new Route(POST, "/{index}/{type}/_mapping"),
new Route(POST, "/{index}/_mapping/{type}"),
new Route(POST, "/_mapping/{type}"),

// register the same paths, but with plural form _mappings
new Route(PUT, "/{index}/{type}/_mappings"),
new Route(PUT, "/{index}/_mappings/{type}"),
new Route(PUT, "/_mappings/{type}"),

new Route(POST, "/{index}/{type}/_mappings"),
new Route(POST, "/{index}/_mappings/{type}"),
new Route(POST, "/_mappings/{type}"),

// no types in path, but type can be provided in body
new Route(POST, "/{index}/_mapping/"),
new Route(PUT, "/{index}/_mapping/"),
new Route(POST, "/{index}/_mappings/"),
new Route(PUT, "/{index}/_mappings/")
);
}

@Override
public String getName() {
return "put_mapping_action_v7";
}

@Override
public Version compatibleWithVersion() {
return Version.V_7_0_0;
}

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);

String type = request.param("type");
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2();
if (includeTypeName == false
&& (type != null || MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap))) {
throw new IllegalArgumentException(
"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
);
}
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
deprecationLogger.deprecate("put_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
}
if (includeTypeName) {
sourceAsMap = prepareMappingsV7(sourceAsMap, request);
}
return super.sendPutMappingRequest(request, client, sourceAsMap);
}

private Map<String, Object> prepareMappingsV7(Map<String, Object> mappings, RestRequest request) {
String typeName = mappings.keySet().iterator().next();
@SuppressWarnings("unchecked")
Map<String, Object> typedMappings = (Map<String, Object>) mappings.get(typeName);

// no matter what the type was, replace it with _doc, because the internal representation still uses single type `_doc`.
return Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, typedMappings);
}
}
2 changes: 2 additions & 0 deletions qa/rest-compat-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ task copyRestTestsResources(type: Copy) {
dependsOn ':distribution:bwc:minor:checkoutBwcBranch'
}

//copyOverrides.dependsOn(copyRestTestsResources)
processTestResources.dependsOn(copyRestTestsResources)
integTest.dependsOn(copyRestTestsResources)

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
setup:
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text

---
"Get field mapping with no index and type":

- do:
indices.get_field_mapping:
include_type_name: true
fields: text
#- match: {test_index.mappings.test_type.text.mapping.text.type: text}
- match: {test_index.mappings._doc.text.mapping.text.type: text}

---
"Get field mapping by index only":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
fields: text
# - match: {test_index.mappings.test_type.text.mapping.text.type: text}
- match: {test_index.mappings._doc.text.mapping.text.type: text}

---
"Get field mapping by type & field":

- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: text
# - match: {test_index.mappings.test_type.text.mapping.text.type: text}
- match: {test_index.mappings._doc.text.mapping.text.type: text}

---
"Get field mapping by type & field, with another field that doesn't exist":

- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: [ text , text1 ]
#- match: {test_index.mappings.test_type.text.mapping.text.type: text}
# - is_false: test_index.mappings.test_type.text1
- match: {test_index.mappings._doc.text.mapping.text.type: text}
- is_false: test_index.mappings._doc.text1

---
"Get field mapping with include_defaults":

- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: text
include_defaults: true
#- match: {test_index.mappings.test_type.text.mapping.text.type: text}
# - match: {test_index.mappings.test_type.text.mapping.text.analyzer: default}
- match: {test_index.mappings._doc.text.mapping.text.type: text}
- match: {test_index.mappings._doc.text.mapping.text.analyzer: default}

---
"Get field mapping should work without index specifying type and fields":

- do:
indices.get_field_mapping:
include_type_name: true
type: test_type
fields: text
# - match: {test_index.mappings.test_type.text.mapping.text.type: text}
- match: {test_index.mappings._doc.text.mapping.text.type: text}

Loading