Skip to content

Deprecate local parameter for get field mapping request #55014

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 9 commits into from
Apr 12, 2020
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 @@ -170,7 +170,6 @@ static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest)
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
parameters.withLocal(getFieldMappingsRequest.local());
request.addParameters(parameters.asMap());
return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/** Request the mappings of specific fields */
public class GetFieldMappingsRequest implements Validatable {

@Deprecated
private boolean local = false;

private String[] fields = Strings.EMPTY_ARRAY;
Expand All @@ -40,11 +41,13 @@ public class GetFieldMappingsRequest implements Validatable {
* Indicate whether the receiving node should operate based on local index information or forward requests,
* where needed, to other nodes. If running locally, request will not raise errors if running locally & missing indices.
*/
@Deprecated
public GetFieldMappingsRequest local(boolean local) {
this.local = local;
return this;
}

@Deprecated
public boolean local() {
return local;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public void testGetFieldMapping() {
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomIndicesOptions(getFieldMappingsRequest::indicesOptions, getFieldMappingsRequest::indicesOptions,
expectedParams);
RequestConvertersTests.setRandomLocal(getFieldMappingsRequest::local, expectedParams);

Request request = IndicesRequestConverters.getFieldMapping(getFieldMappingsRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ public void testGetFieldMapping() throws IOException, InterruptedException {
// end::get-field-mappings-request-local

{

// tag::get-field-mappings-execute
GetFieldMappingsResponse response =
client.indices().getFieldMapping(request, RequestOptions.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ how wildcard expressions are expanded
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-local]
--------------------------------------------------
<1> The `local` flag (defaults to `false`) controls whether the aliases need
<1> deprecated:[7.8.0, This parameter is a no-op and field mappings are always retrieved locally]
The `local` flag (defaults to `false`) controls whether the aliases need
to be looked up in the local cluster state or in the cluster state held by
the elected master node

Expand Down
6 changes: 5 additions & 1 deletion docs/reference/indices/get-field-mapping.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
(Optional, boolean) If `true`, the response includes default mapping values.
Defaults to `false`.

include::{docdir}/rest-api/common-parms.asciidoc[tag=local]
`local`::
deprecated:[7.8.0, This parameter is a no-op and field mappings are always retrieved locally]
(Optional, boolean) If `true`, the request retrieves information from the local
node only. Defaults to `false`, which means information is retrieved from
the master node.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add that the parameter currently is just a noop.

Can you also update the migrate_7_8.asciidoc file when backporting this change to the 7.x branch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Thanks for the heads up about the migrate doc. Will do for 7.x.



[[get-field-mapping-api-example]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,20 @@ setup:

- match: {test_index.mappings.text.mapping.text.type: text}
- match: {test_index.mappings.text.mapping.text.analyzer: default}

---
"Get field mapping with local is deprecated":

- skip:
features: ["warnings", "node_selector"]

- do:
node_selector:
version: "8.0.0 - "
warnings:
- "Use [local] in get field mapping requests is deprecated. The parameter will be removed in the next major version"
indices.get_field_mapping:
fields: text
local: true

- match: {test_index.mappings.text.mapping.text.type: text}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

package org.elasticsearch.rest.action.admin.indices;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
Expand All @@ -43,6 +46,10 @@

public class RestGetFieldMappingAction extends BaseRestHandler {

private static final Logger logger = LogManager.getLogger(RestGetFieldMappingAction.class);
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger);


@Override
public List<Route> routes() {
return List.of(
Expand All @@ -63,6 +70,12 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
GetFieldMappingsRequest getMappingsRequest = new GetFieldMappingsRequest();
getMappingsRequest.indices(indices).fields(fields).includeDefaults(request.paramAsBoolean("include_defaults", false));
getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));

if (request.hasParam("local")) {
deprecationLogger.deprecatedAndMaybeLog("get_field_mapping_local",
"Use [local] in get field mapping requests is deprecated. "
+ "The parameter will be removed in the next major version");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a space between the two sentences?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, added.

}
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
return channel ->
client.admin().indices().getFieldMappings(getMappingsRequest, new RestBuilderListener<>(channel) {
Expand Down