Remove deprecated _suggest endpoint (#22203)
In #20305, _suggest endpoint was deprecated in favour of using _search endpoint. This commit removes the dedicated _suggest endpoint entirely from master.
This commit is contained in:
parent
43f9cd1fd4
commit
d44de0cecc
|
@ -310,7 +310,6 @@ import org.elasticsearch.rest.action.search.RestExplainAction;
|
|||
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
|
||||
import org.elasticsearch.rest.action.search.RestSearchAction;
|
||||
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
|
||||
import org.elasticsearch.rest.action.search.RestSuggestAction;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
@ -550,7 +549,6 @@ public class ActionModule extends AbstractModule {
|
|||
registerRestHandler(handlers, RestMultiGetAction.class);
|
||||
registerRestHandler(handlers, RestDeleteAction.class);
|
||||
registerRestHandler(handlers, org.elasticsearch.rest.action.document.RestCountAction.class);
|
||||
registerRestHandler(handlers, RestSuggestAction.class);
|
||||
registerRestHandler(handlers, RestTermVectorsAction.class);
|
||||
registerRestHandler(handlers, RestMultiTermVectorsAction.class);
|
||||
registerRestHandler(handlers, RestBulkAction.class);
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* 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.search;
|
||||
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.rest.action.RestBuilderListener;
|
||||
import org.elasticsearch.search.SearchRequestParsers;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.suggest.Suggest;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader;
|
||||
|
||||
public class RestSuggestAction extends BaseRestHandler {
|
||||
|
||||
private final SearchRequestParsers searchRequestParsers;
|
||||
|
||||
@Inject
|
||||
public RestSuggestAction(Settings settings, RestController controller,
|
||||
SearchRequestParsers searchRequestParsers) {
|
||||
super(settings);
|
||||
this.searchRequestParsers = searchRequestParsers;
|
||||
controller.registerAsDeprecatedHandler(POST, "/_suggest", this,
|
||||
"[POST /_suggest] is deprecated! Use [POST /_search] instead.", deprecationLogger);
|
||||
controller.registerAsDeprecatedHandler(GET, "/_suggest", this,
|
||||
"[GET /_suggest] is deprecated! Use [GET /_search] instead.", deprecationLogger);
|
||||
controller.registerAsDeprecatedHandler(POST, "/{index}/_suggest", this,
|
||||
"[POST /{index}/_suggest] is deprecated! Use [POST /{index}/_search] instead.", deprecationLogger);
|
||||
controller.registerAsDeprecatedHandler(GET, "/{index}/_suggest", this,
|
||||
"[GET /{index}/_suggest] is deprecated! Use [GET /{index}/_search] instead.", deprecationLogger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
final SearchRequest searchRequest = new SearchRequest(
|
||||
Strings.splitStringByCommaToArray(request.param("index")), new SearchSourceBuilder());
|
||||
searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
|
||||
try (XContentParser parser = request.contentOrSourceParamParser()) {
|
||||
final QueryParseContext context = new QueryParseContext(searchRequestParsers.queryParsers, parser, parseFieldMatcher);
|
||||
searchRequest.source().suggest(SuggestBuilder.fromXContent(context, searchRequestParsers.suggesters));
|
||||
}
|
||||
searchRequest.routing(request.param("routing"));
|
||||
searchRequest.preference(request.param("preference"));
|
||||
return channel -> client.search(searchRequest, new RestBuilderListener<SearchResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception {
|
||||
RestStatus restStatus = RestStatus.status(response.getSuccessfulShards(),
|
||||
response.getTotalShards(), response.getShardFailures());
|
||||
builder.startObject();
|
||||
buildBroadcastShardsHeader(builder, request, response.getTotalShards(),
|
||||
response.getSuccessfulShards(), response.getFailedShards(), response.getShardFailures());
|
||||
Suggest suggest = response.getSuggest();
|
||||
if (suggest != null) {
|
||||
suggest.toInnerXContent(builder, request);
|
||||
}
|
||||
builder.endObject();
|
||||
return new BytesRestResponse(restStatus, builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -150,18 +150,10 @@ public class Suggest implements Iterable<Suggest.Suggestion<? extends Entry<? ex
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
toInnerXContent(builder, params);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* use to write suggestion entries without <code>NAME</code> object
|
||||
*/
|
||||
public XContentBuilder toInnerXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
for (Suggestion<?> suggestion : suggestions) {
|
||||
suggestion.toXContent(builder, params);
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"suggest": {
|
||||
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html",
|
||||
"methods": ["POST"],
|
||||
"url": {
|
||||
"path": "/_suggest",
|
||||
"paths": ["/_suggest", "/{index}/_suggest"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
"description" : "A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices"
|
||||
}
|
||||
},
|
||||
"params": {
|
||||
"ignore_unavailable": {
|
||||
"type" : "boolean",
|
||||
"description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
|
||||
},
|
||||
"allow_no_indices": {
|
||||
"type" : "boolean",
|
||||
"description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"
|
||||
},
|
||||
"expand_wildcards": {
|
||||
"type" : "enum",
|
||||
"options" : ["open","closed","none","all"],
|
||||
"default" : "open",
|
||||
"description" : "Whether to expand wildcard expression to concrete indices that are open, closed or both."
|
||||
},
|
||||
"preference": {
|
||||
"type" : "string",
|
||||
"description" : "Specify the node or shard the operation should be performed on (default: random)"
|
||||
},
|
||||
"routing": {
|
||||
"type" : "string",
|
||||
"description" : "Specific routing value"
|
||||
}
|
||||
}
|
||||
},
|
||||
"body": {
|
||||
"description" : "The request definition",
|
||||
"required" : true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,19 +24,3 @@ setup:
|
|||
- match: {suggest.test_suggestion.1.options.0.text: amsterdam}
|
||||
- match: {suggest.test_suggestion.2.options.0.text: meetup}
|
||||
|
||||
---
|
||||
"Suggest API should have deprecation warning":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
test_suggestion:
|
||||
text: "The Amsterdma meetpu"
|
||||
term:
|
||||
field: body
|
||||
|
||||
- match: {test_suggestion.1.options.0.text: amsterdam}
|
||||
- match: {test_suggestion.2.options.0.text: meetup}
|
||||
|
|
|
@ -1,314 +0,0 @@
|
|||
# This test creates one huge mapping in the setup
|
||||
# Every test should use its own field to make sure it works
|
||||
|
||||
setup:
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test
|
||||
body:
|
||||
mappings:
|
||||
test:
|
||||
"properties":
|
||||
"suggest_1":
|
||||
"type" : "completion"
|
||||
"suggest_2":
|
||||
"type" : "completion"
|
||||
"suggest_3":
|
||||
"type" : "completion"
|
||||
"suggest_4":
|
||||
"type" : "completion"
|
||||
"suggest_5a":
|
||||
"type" : "completion"
|
||||
"suggest_5b":
|
||||
"type" : "completion"
|
||||
"suggest_6":
|
||||
"type" : "completion"
|
||||
title:
|
||||
type: keyword
|
||||
|
||||
---
|
||||
"Simple suggestion should work":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
suggest_1: "bar"
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 2
|
||||
body:
|
||||
suggest_1: "baz"
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_1
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 2 }
|
||||
|
||||
---
|
||||
"Simple suggestion array should work":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
suggest_2: ["bar", "foo"]
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "f"
|
||||
completion:
|
||||
field: suggest_2
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 1 }
|
||||
- match: { result.0.options.0.text: "foo" }
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_2
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 1 }
|
||||
- match: { result.0.options.0.text: "bar" }
|
||||
|
||||
---
|
||||
"Suggestion entry should work":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
suggest_3:
|
||||
input: "bar"
|
||||
weight: 2
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 2
|
||||
body:
|
||||
suggest_3:
|
||||
input: "baz"
|
||||
weight: 3
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_3
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 2 }
|
||||
- match: { result.0.options.0.text: "baz" }
|
||||
- match: { result.0.options.1.text: "bar" }
|
||||
|
||||
---
|
||||
"Suggestion entry array should work":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
suggest_4:
|
||||
- input: "bar"
|
||||
weight: 3
|
||||
- input: "fo"
|
||||
weight: 3
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 2
|
||||
body:
|
||||
suggest_4:
|
||||
- input: "baz"
|
||||
weight: 2
|
||||
- input: "foo"
|
||||
weight: 1
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_4
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 2 }
|
||||
- match: { result.0.options.0.text: "bar" }
|
||||
- match: { result.0.options.1.text: "baz" }
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "f"
|
||||
completion:
|
||||
field: suggest_4
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 2 }
|
||||
- match: { result.0.options.0.text: "fo" }
|
||||
- match: { result.0.options.1.text: "foo" }
|
||||
|
||||
---
|
||||
"Multiple Completion fields should work":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
suggest_5a: "bar"
|
||||
suggest_5b: "baz"
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_5a
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 1 }
|
||||
- match: { result.0.options.0.text: "bar" }
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_5b
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 1 }
|
||||
- match: { result.0.options.0.text: "baz" }
|
||||
|
||||
---
|
||||
"Suggestions with source should work":
|
||||
- skip:
|
||||
features: 'warnings'
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
suggest_6:
|
||||
input: "bar"
|
||||
weight: 2
|
||||
title: "title_bar"
|
||||
count: 4
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test
|
||||
type: test
|
||||
id: 2
|
||||
body:
|
||||
suggest_6:
|
||||
input: "baz"
|
||||
weight: 3
|
||||
title: "title_baz"
|
||||
count: 3
|
||||
|
||||
- do:
|
||||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
warnings:
|
||||
- "[POST /_suggest] is deprecated! Use [POST /_search] instead."
|
||||
suggest:
|
||||
body:
|
||||
result:
|
||||
text: "b"
|
||||
completion:
|
||||
field: suggest_6
|
||||
|
||||
- length: { result: 1 }
|
||||
- length: { result.0.options: 2 }
|
||||
- match: { result.0.options.0.text: "baz" }
|
||||
- match: { result.0.options.0._index: "test" }
|
||||
- match: { result.0.options.0._type: "test" }
|
||||
- match: { result.0.options.0._source.title: "title_baz" }
|
||||
- match: { result.0.options.0._source.count: 3 }
|
||||
- match: { result.0.options.1.text: "bar" }
|
||||
- match: { result.0.options.1._index: "test" }
|
||||
- match: { result.0.options.1._type: "test" }
|
||||
- match: { result.0.options.1._source.title: "title_bar" }
|
||||
- match: { result.0.options.1._source.count: 4 }
|
Loading…
Reference in New Issue