forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the field capabilities API, re-add support for
fields
in the req…
…uest body (elastic#88972) We previously removed support for `fields` in the request body, to ensure there was only one way to specify the parameter. We've now decided to undo the change, since it was disruptive and the request body is actually the best place to pass variable-length data like `fields`. This PR restores support for `fields` in the request body. It throws an error if the parameter is specified both in the URL and the body. Closes elastic#86875
- Loading branch information
Showing
6 changed files
with
109 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Elasticsearch Changlog | ||
# Elasticsearch Changelog | ||
|
||
Please see the [release notes](https://www.elastic.co/guide/en/elasticsearch/reference/current/es-release-notes.html) in the reference manual. |
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,6 @@ | ||
pr: 88972 | ||
summary: In the field capabilities API, re-add support for fields in the request body | ||
area: Search | ||
type: enhancement | ||
issues: | ||
- 86875 |
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
54 changes: 54 additions & 0 deletions
54
server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.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,54 @@ | ||
/* | ||
* 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.rest.action; | ||
|
||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.xcontent.XContentType; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
public class RestFieldCapabilitiesActionTests extends ESTestCase { | ||
|
||
private RestFieldCapabilitiesAction action; | ||
|
||
@Before | ||
public void setUpAction() { | ||
action = new RestFieldCapabilitiesAction(); | ||
} | ||
|
||
public void testRequestBodyAndParamsBothInput() throws IOException { | ||
String content = "{ \"fields\": [\"title\"] }"; | ||
HashMap<String, String> paramsMap = new HashMap<>(); | ||
paramsMap.put("fields", "title"); | ||
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_field_caps") | ||
.withParams(paramsMap) | ||
.withContent(new BytesArray(content), XContentType.JSON) | ||
.build(); | ||
try { | ||
action.prepareRequest(request, mock(NodeClient.class)); | ||
fail("expected failure"); | ||
} catch (IllegalArgumentException e) { | ||
assertEquals( | ||
e.getMessage(), | ||
"can't specify a request body and [fields]" | ||
+ " request parameter, either specify a request body or the" | ||
+ " [fields] request parameter" | ||
); | ||
} | ||
|
||
} | ||
} |