Skip to content

Commit df0a5c1

Browse files
committed
No longer use legacy index templates
1 parent bf24652 commit df0a5c1

File tree

1 file changed

+82
-19
lines changed

1 file changed

+82
-19
lines changed
Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,102 @@
11
# Index templates
22

3-
## Adding an index template named `access-logs`
3+
## Adding/updating an index template
4+
5+
This adds a new index template or updates an existing one.
6+
47
```
5-
PUT /_template/access-logs
8+
PUT /_index_template/access-logs
69
{
710
"index_patterns": ["access-logs-*"],
11+
"template": {
12+
"settings": {
13+
"number_of_shards": 2,
14+
"index.mapping.coerce": false
15+
},
16+
"mappings": {
17+
"properties": {
18+
"@timestamp": { "type": "date" },
19+
"url.original": { "type": "wildcard" },
20+
"url.path": { "type": "wildcard" },
21+
"url.scheme": { "type": "keyword" },
22+
"url.domain": { "type": "keyword" },
23+
"client.geo.continent_name": { "type": "keyword" },
24+
"client.geo.country_name": { "type": "keyword" },
25+
"client.geo.region_name": { "type": "keyword" },
26+
"client.geo.city_name": { "type": "keyword" },
27+
"user_agent.original": { "type": "keyword" },
28+
"user_agent.name": { "type": "keyword" },
29+
"user_agent.version": { "type": "keyword" },
30+
"user_agent.device.name": { "type": "keyword" },
31+
"user_agent.os.name": { "type": "keyword" },
32+
"user_agent.os.version": { "type": "keyword" }
33+
}
34+
}
35+
}
36+
}
37+
```
38+
39+
## Indexing a document into a new index
40+
41+
The index name matches the index pattern defined within the above index template.
42+
The index template's settings and mappings will be therefore be applied to the new index.
43+
44+
```
45+
POST /access-logs-2023-01/_doc
46+
{
47+
"@timestamp": "2023-01-01T00:00:00Z",
48+
"url.original": "https://example.com/products",
49+
"url.path": "/products",
50+
"url.scheme": "https",
51+
"url.domain": "example.com",
52+
"client.geo.continent_name": "Europe",
53+
"client.geo.country_name": "Denmark",
54+
"client.geo.region_name": "Capital City Region",
55+
"client.geo.city_name": "Copenhagen",
56+
"user_agent.original": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1",
57+
"user_agent.name": "Safari",
58+
"user_agent.version": "12.0",
59+
"user_agent.device.name": "iPhone",
60+
"user_agent.os.name": "iOS",
61+
"user_agent.os.version": "12.1.0"
62+
}
63+
```
64+
65+
## Manually creating an index
66+
67+
The index template's settings/mappings will also be applied to this index.
68+
69+
```
70+
PUT /access-logs-2023-02
71+
{
872
"settings": {
9-
"number_of_shards": 2,
10-
"index.mapping.coerce": false
11-
},
73+
"number_of_shards": 1
74+
},
1275
"mappings": {
1376
"properties": {
14-
"@timestamp": {
15-
"type": "date"
16-
},
17-
"url.original": {
18-
"type": "keyword"
19-
},
20-
"http.request.referrer": {
77+
"url.query": {
2178
"type": "keyword"
22-
},
23-
"http.response.status_code": {
24-
"type": "long"
2579
}
2680
}
2781
}
2882
}
2983
```
3084

31-
## Adding an index matching the index template's pattern
85+
## Inspecting the new indices
86+
87+
```
88+
GET /access-logs-2023-01
89+
GET /access-logs-2023-02
90+
```
91+
92+
## Retrieving an index template
93+
3294
```
33-
PUT /access-logs-2020-01-01
95+
GET /_index_template/access-logs
3496
```
3597

36-
## Verify that the mapping is applied
98+
## Deleting an index template
99+
37100
```
38-
GET /access-logs-2020-01-01
101+
DELETE /_index_template/access-logs
39102
```

0 commit comments

Comments
 (0)