Skip to content

Commit d168440

Browse files
committed
Deprecate the _termvector endpoint. (#36098)
This endpoint was replaced by _termvectors (plural) in #8484. We deprecated the relevant transport client methods, but didn't introduce a deprecation warning. My plan was to add a deprecation warning in 6.6, and stop supporting this endpoint in 7.0.
1 parent b3be6d6 commit d168440

File tree

2 files changed

+80
-10
lines changed

2 files changed

+80
-10
lines changed

server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
package org.elasticsearch.rest.action.document;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.elasticsearch.action.termvectors.TermVectorsRequest;
2324
import org.elasticsearch.client.node.NodeClient;
2425
import org.elasticsearch.common.Strings;
26+
import org.elasticsearch.common.logging.DeprecationLogger;
2527
import org.elasticsearch.common.settings.Settings;
2628
import org.elasticsearch.common.xcontent.XContentParser;
2729
import org.elasticsearch.index.VersionType;
@@ -43,18 +45,19 @@
4345
* TermVectorsRequest.
4446
*/
4547
public class RestTermVectorsAction extends BaseRestHandler {
48+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
49+
LogManager.getLogger(RestTermVectorsAction.class));
50+
4651
public RestTermVectorsAction(Settings settings, RestController controller) {
4752
super(settings);
48-
controller.registerHandler(GET, "/{index}/{type}/_termvectors", this);
49-
controller.registerHandler(POST, "/{index}/{type}/_termvectors", this);
50-
controller.registerHandler(GET, "/{index}/{type}/{id}/_termvectors", this);
51-
controller.registerHandler(POST, "/{index}/{type}/{id}/_termvectors", this);
52-
53-
// we keep usage of _termvector as alias for now
54-
controller.registerHandler(GET, "/{index}/{type}/_termvector", this);
55-
controller.registerHandler(POST, "/{index}/{type}/_termvector", this);
56-
controller.registerHandler(GET, "/{index}/{type}/{id}/_termvector", this);
57-
controller.registerHandler(POST, "/{index}/{type}/{id}/_termvector", this);
53+
controller.registerWithDeprecatedHandler(GET, "/{index}/{type}/_termvectors", this,
54+
GET, "/{index}/{type}/_termvector", deprecationLogger);
55+
controller.registerWithDeprecatedHandler(POST, "/{index}/{type}/_termvectors", this,
56+
POST, "/{index}/{type}/_termvector", deprecationLogger);
57+
controller.registerWithDeprecatedHandler(GET, "/{index}/{type}/{id}/_termvectors", this,
58+
GET, "/{index}/{type}/{id}/_termvector", deprecationLogger);
59+
controller.registerWithDeprecatedHandler(POST, "/{index}/{type}/{id}/_termvectors", this,
60+
POST, "/{index}/{type}/{id}/_termvector", deprecationLogger);
5861
}
5962

6063
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.document;
21+
22+
import org.elasticsearch.client.node.NodeClient;
23+
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.common.util.concurrent.ThreadContext;
25+
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
26+
import org.elasticsearch.rest.RestChannel;
27+
import org.elasticsearch.rest.RestController;
28+
import org.elasticsearch.rest.RestRequest;
29+
import org.elasticsearch.rest.RestRequest.Method;
30+
import org.elasticsearch.test.ESTestCase;
31+
import org.elasticsearch.test.rest.FakeRestChannel;
32+
import org.elasticsearch.test.rest.FakeRestRequest;
33+
import org.elasticsearch.usage.UsageService;
34+
35+
import java.util.Collections;
36+
37+
import static org.mockito.Mockito.mock;
38+
39+
public class RestTermVectorsActionTests extends ESTestCase {
40+
private RestController controller;
41+
42+
public void setUp() throws Exception {
43+
super.setUp();
44+
controller = new RestController(Collections.emptySet(), null,
45+
mock(NodeClient.class),
46+
new NoneCircuitBreakerService(),
47+
new UsageService());
48+
new RestTermVectorsAction(Settings.EMPTY, controller);
49+
}
50+
51+
public void testDeprecatedEndpoint() {
52+
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
53+
.withMethod(Method.POST)
54+
.withPath("/some_index/some_type/some_id/_termvector")
55+
.build();
56+
57+
performRequest(request);
58+
assertWarnings("[POST /{index}/{type}/{id}/_termvector] is deprecated! Use" +
59+
" [POST /{index}/{type}/{id}/_termvectors] instead.");
60+
}
61+
62+
private void performRequest(RestRequest request) {
63+
RestChannel channel = new FakeRestChannel(request, false, 1);
64+
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
65+
controller.dispatchRequest(request, channel, threadContext);
66+
}
67+
}

0 commit comments

Comments
 (0)