Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2812b28
Get all scripts from ScriptService
brusic Jan 24, 2018
322f70b
fixed silly assertEquals test with trivial equals()
brusic Jan 25, 2018
9b8406e
update to latest master
brusic Aug 8, 2019
5d4b9ab
backwards compatibility
brusic Aug 13, 2019
74a1a93
Update all code to support old/new interaces. Removed *Scripts* famil…
brusic Aug 14, 2019
2702d6b
Change all /_scripts references to /_script
brusic Aug 15, 2019
3fb53e6
convert /_scripts/painless as well
brusic Aug 15, 2019
73c3a0e
Remove deprecated paths due to potential bug in integration tests
brusic Aug 15, 2019
aa2e84e
Changes based on PR comments. Consistent naming, remove redundancies,…
brusic Aug 21, 2019
23cd4d1
make original format the default
brusic Sep 2, 2019
23cf433
bump up the version
brusic Sep 2, 2019
601e274
Get all scripts from ScriptService
brusic Jan 24, 2018
77fd4d7
fixed silly assertEquals test with trivial equals()
brusic Jan 25, 2018
18d92d8
update to latest master
brusic Aug 8, 2019
e47056d
backwards compatibility
brusic Aug 13, 2019
14156e7
Update all code to support old/new interaces. Removed *Scripts* famil…
brusic Aug 14, 2019
7ea4507
Change all /_scripts references to /_script
brusic Aug 15, 2019
b0ba004
convert /_scripts/painless as well
brusic Aug 15, 2019
e5b6492
Remove deprecated paths due to potential bug in integration tests
brusic Aug 15, 2019
ac4605b
Changes based on PR comments. Consistent naming, remove redundancies,…
brusic Aug 21, 2019
ff19531
make original format the default
brusic Sep 2, 2019
308ed45
bump up the version
brusic Sep 2, 2019
b913f9c
Merge branch 'get-all-scripts' of github.com:brusic/elasticsearch int…
brusic Sep 3, 2019
086d9ac
fix new format bug
brusic Sep 3, 2019
3103e1d
disable bwc tests
brusic Sep 12, 2019
44675c4
Merge remote-tracking branch 'upstream/master' into get-all-scripts
brusic Jun 2, 2020
f7c76b2
update more legacy paths
brusic Jun 2, 2020
67f24ba
remove renamed file
brusic Jun 3, 2020
10794af
more name changes
brusic Jun 3, 2020
4d39538
cleanup API
brusic Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ tasks.register("verifyVersions") {
* after the backport of the backcompat code is complete.
*/

boolean bwc_tests_enabled = true
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
boolean bwc_tests_enabled = false
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/28368" /* place a PR link here when committing bwc changes */
if (bwc_tests_enabled == false) {
if (bwc_tests_disabled_issue.isEmpty()) {
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ private static Request rethrottle(RethrottleRequest rethrottleRequest, String fi
}

static Request putScript(PutStoredScriptRequest putStoredScriptRequest) throws IOException {
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(putStoredScriptRequest.id()).build();
String endpoint = new EndpointBuilder().addPathPartAsIs("_script").addPathPart(putStoredScriptRequest.id()).build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
Params params = new Params();
params.withTimeout(putStoredScriptRequest.timeout());
Expand Down Expand Up @@ -718,7 +718,7 @@ static Request mtermVectors(MultiTermVectorsRequest mtvrequest) throws IOExcepti
}

static Request getScript(GetStoredScriptRequest getStoredScriptRequest) {
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(getStoredScriptRequest.id()).build();
String endpoint = new EndpointBuilder().addPathPartAsIs("_script").addPathPart(getStoredScriptRequest.id()).build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
Params params = new Params();
params.withMasterTimeout(getStoredScriptRequest.masterNodeTimeout());
Expand All @@ -727,7 +727,7 @@ static Request getScript(GetStoredScriptRequest getStoredScriptRequest) {
}

static Request deleteScript(DeleteStoredScriptRequest deleteStoredScriptRequest) {
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(deleteStoredScriptRequest.id()).build();
String endpoint = new EndpointBuilder().addPathPartAsIs("_script").addPathPart(deleteStoredScriptRequest.id()).build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
Params params = new Params();
params.withTimeout(deleteStoredScriptRequest.timeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ public void testPutScript() throws Exception {

Request request = RequestConverters.putScript(putStoredScriptRequest);

assertThat(request.getEndpoint(), equalTo("/_scripts/" + id));
assertThat(request.getEndpoint(), equalTo("/_script/" + id));
assertThat(request.getParameters(), equalTo(expectedParams));
assertNotNull(request.getEntity());
assertToXContentBody(putStoredScriptRequest, request.getEntity());
Expand All @@ -1611,7 +1611,7 @@ public void testGetScriptRequest() {
setRandomMasterTimeout(getStoredScriptRequest, expectedParams);

Request request = RequestConverters.getScript(getStoredScriptRequest);
assertThat(request.getEndpoint(), equalTo("/_scripts/" + getStoredScriptRequest.id()));
assertThat(request.getEndpoint(), equalTo("/_script/" + getStoredScriptRequest.id()));
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(request.getParameters(), equalTo(expectedParams));
assertThat(request.getEntity(), nullValue());
Expand All @@ -1625,7 +1625,7 @@ public void testDeleteScriptRequest() {
setRandomMasterTimeout(deleteStoredScriptRequest, expectedParams);

Request request = RequestConverters.deleteScript(deleteStoredScriptRequest);
assertThat(request.getEndpoint(), equalTo("/_scripts/" + deleteStoredScriptRequest.id()));
assertThat(request.getEndpoint(), equalTo("/_script/" + deleteStoredScriptRequest.id()));
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
assertThat(request.getParameters(), equalTo(expectedParams));
assertThat(request.getEntity(), nullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public void testApiNamingConventions() throws Exception {
"indices.get_upgrade",
"indices.put_alias",
"render_search_template",
"scripts_painless_execute",
"script_painless_execute",
"indices.create_data_stream",
"indices.get_data_stream",
"indices.delete_data_stream",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGetStoredScript() throws Exception {
GetStoredScriptResponse getResponse = execute(getRequest, highLevelClient()::getScript,
highLevelClient()::getScriptAsync);

assertThat(getResponse.getSource(), equalTo(scriptSource));
assertThat(getResponse.getStoredScript("calculate-score"), equalTo(scriptSource));
}

public void testDeleteStoredScript() throws Exception {
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testPutScript() throws Exception {
new PutStoredScriptRequest(id, "score", new BytesArray("{}"), XContentType.JSON, scriptSource);
assertAcked(execute(request, highLevelClient()::putScript, highLevelClient()::putScriptAsync));

Map<String, Object> script = getAsMap("/_scripts/" + id);
Map<String, Object> script = getAsMap("/_script/" + id);
assertThat(extractValue("_id", script), equalTo(id));
assertThat(extractValue("found", script), equalTo(true));
assertThat(extractValue("script.lang", script), equalTo("painless"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void testUpdate() throws Exception {
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
assertSame(RestStatus.CREATED, indexResponse.status());

Request request = new Request("POST", "/_scripts/increment-field");
Request request = new Request("POST", "/_script/increment-field");
request.setJsonEntity(Strings.toString(JsonXContent.contentBuilder()
.startObject()
.startObject("script")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public void onFailure(Exception e) {

protected void registerQueryScript(RestClient restClient) throws IOException {
// tag::register-script
Request scriptRequest = new Request("POST", "_scripts/title_search");
Request scriptRequest = new Request("POST", "_script/title_search");
scriptRequest.setJsonEntity(
"{" +
" \"script\": {" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testGetStoredScript() throws Exception {
// end::get-stored-script-execute

// tag::get-stored-script-response
StoredScriptSource storedScriptSource = getResponse.getSource(); // <1>
StoredScriptSource storedScriptSource = getResponse.getStoredScript("calculate-score"); // <1>

String lang = storedScriptSource.getLang(); // <2>
String source = storedScriptSource.getSource(); // <3>
Expand All @@ -105,7 +105,7 @@ public void testGetStoredScript() throws Exception {

// tag::get-stored-script-execute-listener
ActionListener<GetStoredScriptResponse> listener =
new ActionListener<GetStoredScriptResponse>() {
new ActionListener<>() {
@Override
public void onResponse(GetStoredScriptResponse response) {
// <1>
Expand Down Expand Up @@ -168,7 +168,7 @@ public void testDeleteStoredScript() throws Exception {

// tag::delete-stored-script-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
new ActionListener<>() {
@Override
public void onResponse(AcknowledgedResponse response) {
// <1>
Expand Down Expand Up @@ -256,7 +256,7 @@ public void testPutScript() throws Exception {

// tag::put-stored-script-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
new ActionListener<>() {
@Override
public void onResponse(AcknowledgedResponse response) {
// <1>
Expand Down Expand Up @@ -301,7 +301,7 @@ public void onFailure(Exception e) {

client.putScript(request, RequestOptions.DEFAULT);

Map<String, Object> script = getAsMap("/_scripts/id");
Map<String, Object> script = getAsMap("/_script/id");
assertThat(extractValue("script.lang", script), equalTo("mustache"));
assertThat(extractValue("script.source", script), equalTo("{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testSimulatePipelineMissingBody() throws IOException {

public void testPutScriptMissingBody() throws IOException {
ResponseException responseException = expectThrows(ResponseException.class, () ->
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/_scripts/lang")));
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/_script/lang")));
assertResponseException(responseException, "request body is required");
}

Expand Down
6 changes: 3 additions & 3 deletions docs/painless/painless-guide/painless-execute-script.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Request:

[source,console]
----------------------------------------------------------------
POST /_scripts/painless/_execute
POST /_script/painless/_execute
{
"script": {
"source": "params.count / params.total",
Expand Down Expand Up @@ -80,7 +80,7 @@ PUT /my-index
}
}

POST /_scripts/painless/_execute
POST /_script/painless/_execute
{
"script": {
"source": "doc['field'].value.length() <= params.max_length",
Expand Down Expand Up @@ -138,7 +138,7 @@ PUT /my-index
}


POST /_scripts/painless/_execute
POST /_script/painless/_execute
{
"script": {
"source": "doc['rank'].value / params.max_rank",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ It is also possible to use stored scripts. Here is a simple stored script:

[source,console,id=range-aggregation-stored-script-example]
--------------------------------------------------
POST /_scripts/convert_currency
POST /_script/convert_currency
{
"script": {
"lang": "painless",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ This will interpret the `script` parameter as an `inline` script with the defaul

[source,console,id=terms-aggregation-stored-example]
--------------------------------------------------
POST /_scripts/my_script
POST /_script/my_script
{
"script": {
"lang": "painless",
Expand Down
16 changes: 8 additions & 8 deletions docs/reference/scripting/using.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ The same script in the normal form:
=== Stored scripts

Scripts may be stored in and retrieved from the cluster state using the
`_scripts` end-point.
`_script` end-point.

[float]
==== Request examples

The following are examples of using a stored script that lives at
`/_scripts/{id}`.
`/_script/{id}`.

First, create the script called `calculate-score` in the cluster state:

[source,console]
-----------------------------------
POST _scripts/calculate-score
POST _script/calculate-score
{
"script": {
"lang": "painless",
Expand All @@ -159,11 +159,11 @@ POST _scripts/calculate-score

You may also specify a context as part of the url path to compile a
stored script against that specific context in the form of
`/_scripts/{id}/{context}`:
`/_script/{id}/{context}`:

[source,console]
-----------------------------------
POST _scripts/calculate-score/score
POST _script/calculate-score/score
{
"script": {
"lang": "painless",
Expand All @@ -177,7 +177,7 @@ This same script can be retrieved with:

[source,console]
-----------------------------------
GET _scripts/calculate-score
GET _script/calculate-score
-----------------------------------
// TEST[continued]

Expand Down Expand Up @@ -210,14 +210,14 @@ And deleted with:

[source,console]
-----------------------------------
DELETE _scripts/calculate-score
DELETE _script/calculate-score
-----------------------------------
// TEST[continued]

[float]
[[modules-scripting-search-templates]]
=== Search templates
You can also use the `_scripts` API to store **search templates**. Search
You can also use the `_script` API to store **search templates**. Search
templates save specific <<search-search,search requests>> with placeholder
values, called template parameters.

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/search/multi-search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ You can also create search templates:

[source,console]
------------------------------------------
POST /_scripts/my_template_1
POST /_script/my_template_1
{
"script": {
"lang": "mustache",
Expand All @@ -351,7 +351,7 @@ POST /_scripts/my_template_1

[source,console]
------------------------------------------
POST /_scripts/my_template_2
POST /_script/my_template_2
{
"script": {
"lang": "mustache",
Expand Down
12 changes: 5 additions & 7 deletions docs/reference/search/search-template.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ You can store a search template using the stored scripts API.

[source,console]
------------------------------------------
POST _scripts/<templateid>
POST _script/<templateid>
{
"script": {
"lang": "mustache",
Expand Down Expand Up @@ -145,7 +145,7 @@ The template can be retrieved by calling

[source,console]
------------------------------------------
GET _scripts/<templateid>
GET _script/<templateid>?new_format=true
------------------------------------------
// TEST[continued]

Expand All @@ -154,15 +154,13 @@ The API returns the following result:
[source,console-result]
------------------------------------------
{
"script" : {
"<templateid>" : {
"lang" : "mustache",
"source" : "{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}",
"options": {
"content_type" : "application/json; charset=UTF-8"
}
},
"_id": "<templateid>",
"found": true
}
}
------------------------------------------

Expand All @@ -171,7 +169,7 @@ This template can be deleted by calling

[source,console]
------------------------------------------
DELETE _scripts/<templateid>
DELETE _script/<templateid>
------------------------------------------
// TEST[continued]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public void testIndexedTemplateClient() throws Exception {

GetStoredScriptResponse getResponse = client().admin().cluster()
.prepareGetStoredScript("testTemplate").get();
assertNotNull(getResponse.getSource());
assertEquals(1, getResponse.getStoredScripts().size());
assertNotNull(getResponse.getStoredScript("testTemplate"));

BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
bulkRequestBuilder.add(client().prepareIndex("test").setId("1").setSource("{\"theField\":\"foo\"}", XContentType.JSON));
Expand All @@ -192,8 +193,8 @@ public void testIndexedTemplateClient() throws Exception {

assertAcked(client().admin().cluster().prepareDeleteStoredScript("testTemplate"));

getResponse = client().admin().cluster().prepareGetStoredScript("testTemplate").get();
assertNull(getResponse.getSource());
final GetStoredScriptResponse response = client().admin().cluster().prepareGetStoredScript("testTemplate").get();
assertNull(response.getStoredScript("testTemplate"));
}

public void testIndexedTemplate() throws Exception {
Expand Down Expand Up @@ -291,7 +292,7 @@ public void testIndexedTemplateOverwrite() throws Exception {
);

GetStoredScriptResponse getResponse = client().admin().cluster().prepareGetStoredScript("git01").get();
assertNotNull(getResponse.getSource());
assertNotNull(getResponse.getStoredScript("git01"));

Map<String, Object> templateParams = new HashMap<>();
templateParams.put("P_Keyword1", "dev");
Expand Down
2 changes: 1 addition & 1 deletion modules/lang-painless/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencyLicenses {
restResources {
restApi {
includeCore '_common', 'cluster', 'nodes', 'indices', 'index', 'search', 'get', 'bulk', 'update',
'scripts_painless_execute', 'put_script', 'delete_script'
'script_painless_execute', 'put_script', 'delete_script'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void main(String[] args) throws IOException {
@SuppressForbidden(reason = "retrieving data from an internal API not exposed as part of the REST client")
private static List<PainlessContextInfo> getContextInfos() throws IOException {
URLConnection getContextNames = new URL(
"http://" + System.getProperty("cluster.uri") + "/_scripts/painless/_context").openConnection();
"http://" + System.getProperty("cluster.uri") + "/_script/painless/_context").openConnection();
XContentParser parser = JsonXContent.jsonXContent.createParser(null, null, getContextNames.getInputStream());
parser.nextToken();
parser.nextToken();
Expand All @@ -118,7 +118,7 @@ private static List<PainlessContextInfo> getContextInfos() throws IOException {

for (String contextName : contextNames) {
URLConnection getContextInfo = new URL(
"http://" + System.getProperty("cluster.uri") + "/_scripts/painless/_context?context=" + contextName).openConnection();
"http://" + System.getProperty("cluster.uri") + "/_script/painless/_context?context=" + contextName).openConnection();
parser = JsonXContent.jsonXContent.createParser(null, null, getContextInfo.getInputStream());
contextInfos.add(PainlessContextInfo.fromXContent(parser));
((HttpURLConnection)getContextInfo).disconnect();
Expand Down
Loading