Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-templates APIs don't support lists #78989

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions docs/reference/cat/templates.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ and <<mapping,field mappings>> to new indices at creation.
==== {api-path-parms-title}

`<template_name>`::
(Optional, string) Comma-separated list of index template names used to limit
the request. Accepts wildcard expressions.

(Optional, string) The name of the template to return. Accepts wildcard
expressions. If omitted, all templates are returned.

[[cat-templates-query-params]]
==== {api-query-parms-title}
Expand Down
6 changes: 2 additions & 4 deletions docs/reference/indices/get-index-template.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ privilege>> to use this API.
[[get-template-api-path-params]]
==== {api-path-parms-title}

include::{docdir}/rest-api/common-parms.asciidoc[tag=index-template]
+
To retrieve all index templates, omit this parameter or use a value of `*`.

(Optional, string) The name of the template to return. Accepts wildcard
expressions. If omitted, all templates are returned.

[[get-template-api-query-params]]
==== {api-query-parms-title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
],
"parts":{
"name":{
"type":"list",
"description":"The comma separated names of the index templates"
"type":"string",
"description":"A pattern that returned template names must match"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,6 @@ setup:
- match:
$body: /test-composable-1\ntest-composable-2\ntest-legacy-1\ntest-legacy-2\n/

---
"Matching all templates with other patterns":
- skip:
version: " - 7.99.99"
reason: "support for multiple patterns added in 8.0.0"

- do:
cat.templates:
name: "nonexistent*,*,other-name"
h: [name]
s: [name]

- match:
$body: /test-composable-1\ntest-composable-2\ntest-legacy-1\ntest-legacy-2\n/

---
"Matching no templates":

Expand Down Expand Up @@ -146,41 +131,13 @@ setup:
- match:
$body: /^test-composable-2\ntest-legacy-2\n$/

---
"Matching lists of names":
- skip:
version: " - 7.99.99"
reason: "support for multiple patterns added in 8.0.0"

- do:
cat.templates:
name: "test-legacy-1,test-composable-2"
h: [name]
s: [name]

- match:
$body: /^test-composable-2\ntest-legacy-1\n$/

---
"Matching names and wildcards":
- skip:
version: " - 7.99.99"
reason: "support for multiple patterns added in 8.0.0"

- do:
cat.templates:
name: "test-legacy-1,test-composable-*"
h: [name]
s: [name]

- match:
$body: /^test-composable-1\ntest-composable-2\ntest-legacy-1\n$/

- do:
cat.templates:
name: "test-legacy-*,test-composable-2"
h: [name]
s: [name]

- match:
$body: /^test-composable-2\ntest-legacy-1\ntest-legacy-2\n$/
"Reject request containing comma":
- skip:
version: " - 7.99.99"
reason: "validation only added in 8.0.0"
- do:
catch: bad_request
cat.templates:
name: test1,test2
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,43 @@ setup:
- is_true: index_templates.0.name
- is_true: index_templates.1.name

---
"Pattern matching in index templates":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"
features: allowed_warnings

- do:
allowed_warnings:
- "index template [test2] has index patterns [test2-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test2] will take precedence during new index creation"
indices.put_index_template:
name: test2
body:
index_patterns: test2-*
template:
settings:
number_of_shards: 1

- do:
indices.get_index_template:
name: "*"

- is_true: index_templates.0.name
- is_true: index_templates.1.name

- do:
indices.get_index_template:
name: "test*"

- match: { index_templates.0.name: "/test.*/" }
- match: { index_templates.1.name: "/test.*/" }

---
"Get index template with local flag":
- skip:
version: " - 7.99.99"
reason: "index template v2 API has not been backported"
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"
Comment on lines +97 to +98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this


- do:
indices.get_index_template:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
setup:
- skip:
version: " - 7.99.99"
reason: "index template v2 API has not been backported"
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.delete_index_template:
name: '*'
ignore: 404

---
"Get missing template":
- skip:
version: " - 7.99.99"
reason: "index template v2 API has not been backported"
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
catch: missing
indices.get_index_template:
name: test
name: nonexistent

- match: { error.reason: "index template matching [nonexistent] not found" }

---
"Get non-matching wildcard":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
catch: missing
indices.get_index_template:
name: "non-matching-wildcard*"

- is_false: error
- is_true: index_templates

---
"Reject request containing comma":
- skip:
version: " - 7.99.99"
reason: "validation only added in 8.0.0"
- do:
catch: bad_request
indices.get_index_template:
name: test1,test2
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;

Expand All @@ -39,11 +39,15 @@ private GetComposableIndexTemplateAction() {
public static class Request extends MasterNodeReadRequest<Request> {

@Nullable
private String name;

public Request() { }
private final String name;

/**
* @param name A template name or pattern, or {@code null} to retrieve all templates.
*/
public Request(@Nullable String name) {
if (name != null && name.contains(",")) {
throw new IllegalArgumentException("template name may not contain ','");
}
this.name = name;
}

Expand All @@ -63,14 +67,6 @@ public ActionRequestValidationException validate() {
return null;
}

/**
* Sets the name of the index template.
*/
public Request name(String name) {
this.name = name;
return this;
}

/**
* The name of the index templates.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
*/
public class GetIndexTemplatesRequest extends MasterNodeReadRequest<GetIndexTemplatesRequest> {

private String[] names;

public GetIndexTemplatesRequest() {
}
private final String[] names;

public GetIndexTemplatesRequest(String... names) {
this.names = names;
Expand Down Expand Up @@ -57,14 +54,6 @@ public ActionRequestValidationException validate() {
return validationException;
}

/**
* Sets the names of the index templates.
*/
public GetIndexTemplatesRequest names(String... names) {
this.names = names;
return this;
}

/**
* The names of the index templates.
*/
Expand Down
Loading