Skip to content

Commit

Permalink
[Rest Api Compatibility] Typed endpoints for search _count api
Browse files Browse the repository at this point in the history
retrofits typed endpoints removed in elastic#42112

relates elastic#51816
 Please enter the commit message for your changes. Lines starting
  • Loading branch information
pgomulka committed Jun 9, 2021
1 parent ff83531 commit 468a751
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ tasks.named("yamlRestCompatTest").configure {
// 89 - 15 = 74 tests won't be fixed
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion and specifying both node_ids and node_names',
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion without specifying nodes',
'count/11_basic_with_types/count body without query element',
'count/11_basic_with_types/count with body',
'count/11_basic_with_types/count with empty body',
// 'count/11_basic_with_types/count body without query element',
// 'count/11_basic_with_types/count with body',
// 'count/11_basic_with_types/count with empty body',
'field_caps/30_filter/Field caps with index filter',
'get_source/11_basic_with_types/Basic with types',
'get_source/16_default_values_with_types/Default values',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
Expand All @@ -32,14 +33,20 @@
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;

public class RestCountAction extends BaseRestHandler {

static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in count requests is deprecated.";
@Override
public List<Route> routes() {
return List.of(
new Route(GET, "/_count"),
new Route(POST, "/_count"),
new Route(GET, "/{index}/_count"),
new Route(POST, "/{index}/_count"));
new Route(POST, "/{index}/_count"),
Route.builder(GET, "/{index}/{type}/_count")
.deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
.build(),
Route.builder(POST, "/{index}/{type}/_count")
.deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
.build());
}

@Override
Expand All @@ -49,6 +56,9 @@ public String getName() {

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("type")) {
request.param("type");
}
SearchRequest countRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")));
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0).trackTotalHits(true);
Expand Down

0 comments on commit 468a751

Please sign in to comment.