-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rest Api Compatibility] Typed endpoints for search and related endpo…
…ints (#72155) Implements a V7 compatible typed endpoints for REST for search related apis retrofits the REST layer change removed in #41640 relates main meta issue #51816 relates types removal issue #54160
- Loading branch information
Showing
27 changed files
with
688 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...e/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.script.mustache; | ||
|
||
import org.elasticsearch.common.RestApiVersion; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RestMultiSearchTemplateActionTests extends RestActionTestCase { | ||
final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); | ||
|
||
@Before | ||
public void setUpAction() { | ||
controller().registerHandler(new RestMultiSearchTemplateAction(Settings.EMPTY)); | ||
//todo how to workaround this? we get AssertionError without this | ||
verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class)); | ||
verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class)); | ||
} | ||
|
||
public void testTypeInPath() { | ||
String content = "{ \"index\": \"some_index\" } \n" + | ||
"{\"source\": {\"query\" : {\"match_all\" :{}}}} \n"; | ||
BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8)); | ||
|
||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.GET) | ||
.withPath("/some_index/some_type/_msearch/template") | ||
.withContent(bytesContent, null) | ||
.build(); | ||
|
||
dispatchRequest(request); | ||
assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE); | ||
} | ||
|
||
public void testTypeInBody() { | ||
String content = "{ \"index\": \"some_index\", \"type\": \"some_type\" } \n" + | ||
"{\"source\": {\"query\" : {\"match_all\" :{}}}} \n"; | ||
BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8)); | ||
|
||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) | ||
.withPath("/some_index/_msearch/template") | ||
.withContent(bytesContent, null) | ||
.build(); | ||
|
||
dispatchRequest(request); | ||
assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...stache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.script.mustache; | ||
|
||
import org.elasticsearch.common.RestApiVersion; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.search.RestSearchAction; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RestSearchTemplateActionTests extends RestActionTestCase { | ||
final List<String> contentTypeHeader = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7)); | ||
|
||
@Before | ||
public void setUpAction() { | ||
controller().registerHandler(new RestSearchTemplateAction()); | ||
verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(SearchTemplateResponse.class)); | ||
verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(SearchTemplateResponse.class)); | ||
} | ||
|
||
public void testTypeInPath() { | ||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.GET) | ||
.withPath("/some_index/some_type/_search/template") | ||
.build(); | ||
|
||
dispatchRequest(request); | ||
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE); | ||
} | ||
|
||
public void testTypeParameter() { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("type", "some_type"); | ||
|
||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.GET) | ||
.withPath("/some_index/_search/template") | ||
.withParams(params) | ||
.build(); | ||
|
||
dispatchRequest(request); | ||
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...s/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.reindex; | ||
|
||
import org.elasticsearch.common.RestApiVersion; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.search.RestSearchAction; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RestDeleteByQueryActionTests extends RestActionTestCase { | ||
|
||
final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); | ||
|
||
@Before | ||
public void setUpAction() { | ||
controller().registerHandler(new RestDeleteByQueryAction()); | ||
verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class)); | ||
verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class)); | ||
} | ||
|
||
public void testTypeInPath() throws IOException { | ||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.POST) | ||
.withPath("/some_index/some_type/_delete_by_query") | ||
.build(); | ||
|
||
// checks the type in the URL is propagated correctly to the request object | ||
// only works after the request is dispatched, so its params are filled from url. | ||
dispatchRequest(request); | ||
|
||
|
||
// RestDeleteByQueryAction itself doesn't check for a deprecated type usage | ||
// checking here for a deprecation from its internal search request | ||
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...s/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.reindex; | ||
|
||
import org.elasticsearch.common.RestApiVersion; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.search.RestSearchAction; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RestUpdateByQueryActionTests extends RestActionTestCase { | ||
|
||
final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); | ||
|
||
@Before | ||
public void setUpAction() { | ||
controller().registerHandler(new RestUpdateByQueryAction()); | ||
verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class)); | ||
verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class)); | ||
} | ||
|
||
public void testTypeInPath() throws IOException { | ||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.POST) | ||
.withPath("/some_index/some_type/_update_by_query") | ||
.build(); | ||
|
||
// checks the type in the URL is propagated correctly to the request object | ||
// only works after the request is dispatched, so its params are filled from url. | ||
dispatchRequest(request); | ||
|
||
// RestUpdateByQueryAction itself doesn't check for a deprecated type usage | ||
// checking here for a deprecation from its internal search request | ||
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE); | ||
} | ||
} |
Oops, something went wrong.