Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit ff4dd7c

Browse files
authored
Merge pull request #33 from inloco/fix/index-templates
Fix/index templates
2 parents 502c9b6 + 01ce956 commit ff4dd7c

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ your mappings based on the kind of data you are sending. This is fine for some u
4545
strongly recommend that you create your own mappings (Especially if you care about your date
4646
types). If you are using multiple indexes, a index template is something that you should look into.
4747

48-
If you are planning on using kibana as an analytics tool, is recommended to use a template for your data like belows.
48+
If you are planning on using Kibana as an analytics tool, is recommended to use a template for your data like belows.
4949

50-
### Setting up a template in Elastic Search
51-
52-
> Note: This step only works with elastic search 5.5.0 and above.
50+
### Setting up a template in Elasticsearch
5351

5452
Index templates allow you to define templates that will automatically be applied when new indices are created. In this
5553
example, a wildcard (*) is used and every new index following this pattern will use the template configuration.
5654

57-
To set a template for some index, send a PUT REST method to: ```http://elasticsearch:9200/_template/sample-logs ``` with belows JSON
58-
file.
55+
To set a template for some index, send a PUT REST method to: ```http://elasticsearch:9200/_template/sample-logs``` with
56+
the JSON below that matches your Elasticsearch version.
57+
58+
#### 5.5.x ~ 6.8.x
59+
60+
> The _\_default\__ field is deprecated for versions above 6.x, but still supported.
5961
6062
```json
6163
{
@@ -91,17 +93,47 @@ file.
9193
}
9294
```
9395

94-
This template does the following
96+
##### 7.0.0 and above
97+
```json
98+
{
99+
"template": "sample-logs-*",
100+
"mappings": {
101+
"_source": {
102+
"enabled": "true"
103+
},
104+
"properties": {
105+
"timestamp": {
106+
"type": "date",
107+
"format": "date_optional_time",
108+
"ignore_malformed": true
109+
}
110+
},
111+
"dynamic_templates": [
112+
{
113+
"strings": {
114+
"match_mapping_type": "string",
115+
"mapping": {
116+
"type": "text",
117+
"index": false
118+
}
119+
}
120+
}
121+
]
122+
}
123+
}
124+
```
125+
126+
Both templates do the following things:
95127

96128
- Makes all strings not analyzed by default. If you want/need analyzed fields, you can either remove
97129
the dynamic template for "strings" or add your field as a property
98130
- Adds a date property to be used as a time field. Replace according to your field name and format.
99131
- Sets the `_default_` type. Matches all types and acts as a base. You can override settings or set
100-
new properties by adding other types.
101-
- If your're using a timestamp with milliseconds, use ```epoch_millis``` as format for date type.
132+
new properties by adding other types. For versions above `7.0.0`, the behavior is the same, but the
133+
field was removed. You can read more about this [here][removal_of_mapping_types].
134+
- If you're using a timestamp with milliseconds, use ```epoch_millis``` as format for date type.
102135

103-
You can find more information here: [Indices Templates][indices_templates], [Mapping Changes][mapping_changes],
104-
[Date datatype][date_datatype]
136+
You can find more information here: [Indices Templates][indices_templates], [Date datatype][date_datatype]
105137

106138
### Monitoring
107139

@@ -135,6 +167,6 @@ Please update this file before merging any PRs to the master branch.
135167
When a `git push` is triggered, CircleCI will run the project's tests and push the generated docker image to dockerhub.
136168
If the current branch is master, the docker tag will be `<version>`. If not, it will be `<version>-<commit-sha>`
137169

138-
[mapping_changes]: https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_mapping_changes.html
139170
[indices_templates]: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
140171
[date_datatype]: https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html
172+
[removal_of_mapping_types]: https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

0 commit comments

Comments
 (0)