Skip to content

Commit 92113c3

Browse files
authored
Submit async search to work only with POST (#53368)
Currently the submit async search API can be called using both GET and POST at REST, but given that it submits a call and creates internal state, POST should be the only allowed method.
1 parent 9dcd88e commit 92113c3

File tree

3 files changed

+4
-20
lines changed

3 files changed

+4
-20
lines changed

x-pack/plugin/async-search/qa/security/src/test/java/org/elasticsearch/xpack/search/AsyncSearchSecurityIT.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected Settings restClientSettings() {
4444
}
4545

4646
@Before
47-
private void indexDocuments() throws IOException {
47+
public void indexDocuments() throws IOException {
4848
createIndex("index", Settings.EMPTY);
4949
index("index", "0", "foo", "bar");
5050
refresh("index");
@@ -122,12 +122,8 @@ static Response get(String index, String id, String user) throws IOException {
122122
return client().performRequest(request);
123123
}
124124

125-
static Response submitAsyncSearch(String indexName, String query, String user) throws IOException {
126-
return submitAsyncSearch(indexName, query, TimeValue.MINUS_ONE, user);
127-
}
128-
129125
static Response submitAsyncSearch(String indexName, String query, TimeValue waitForCompletion, String user) throws IOException {
130-
final Request request = new Request("GET", indexName + "/_async_search");
126+
final Request request = new Request("POST", indexName + "/_async_search");
131127
setRunAsHeader(request, user);
132128
request.addParameter("q", query);
133129
request.addParameter("wait_for_completion", waitForCompletion.toString());
@@ -136,13 +132,6 @@ static Response submitAsyncSearch(String indexName, String query, TimeValue wait
136132
return client().performRequest(request);
137133
}
138134

139-
static Response search(String indexName, String query, String user) throws IOException {
140-
final Request request = new Request("GET", indexName + "/_search");
141-
setRunAsHeader(request, user);
142-
request.addParameter("q", query);
143-
return client().performRequest(request);
144-
}
145-
146135
static Response getAsyncSearch(String id, String user) throws IOException {
147136
final Request request = new Request("GET", "/_async_search/" + id);
148137
setRunAsHeader(request, user);

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/RestSubmitAsyncSearchAction.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
import java.io.IOException;
1818
import java.util.Collections;
19+
import java.util.List;
1920
import java.util.Set;
2021
import java.util.function.IntConsumer;
21-
import java.util.List;
2222

2323
import static java.util.Arrays.asList;
2424
import static java.util.Collections.unmodifiableList;
25-
import static org.elasticsearch.rest.RestRequest.Method.GET;
2625
import static org.elasticsearch.rest.RestRequest.Method.POST;
2726
import static org.elasticsearch.rest.action.search.RestSearchAction.parseSearchRequest;
2827

@@ -34,9 +33,7 @@ public final class RestSubmitAsyncSearchAction extends BaseRestHandler {
3433
public List<Route> routes() {
3534
return unmodifiableList(asList(
3635
new Route(POST, "/_async_search"),
37-
new Route(GET, "/_async_search"),
38-
new Route(POST, "/{index}/_async_search"),
39-
new Route(GET, "/{index}/_async_search")));
36+
new Route(POST, "/{index}/_async_search")));
4037
}
4138

4239
@Override

x-pack/plugin/src/test/resources/rest-api-spec/api/async_search.submit.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
{
1010
"path":"/_async_search",
1111
"methods":[
12-
"GET",
1312
"POST"
1413
]
1514
},
1615
{
1716
"path":"/{index}/_async_search",
1817
"methods":[
19-
"GET",
2018
"POST"
2119
],
2220
"parts":{

0 commit comments

Comments
 (0)