|
| 1 | +--- |
| 2 | +title: Index template configuration |
| 3 | +sidebar_position: 7 |
| 4 | +toc_max_heading_level: 4 |
| 5 | +--- |
| 6 | + |
| 7 | +This page describes how to configure an index template. |
| 8 | + |
| 9 | +Index templates let you dynamically create indexes according to predefined rules. Templates are used automatically when documents are received on the ingest API for an index that doesn't exist. |
| 10 | + |
| 11 | +The index template configuration lets you define the following parameters: |
| 12 | +- `template_id` (required) |
| 13 | +- `description` |
| 14 | +- `index_id_patterns` (required) |
| 15 | +- `index_root_uri` |
| 16 | +- `priority` |
| 17 | + |
| 18 | +Besides, the following parameters can also be configured and are the same as those found in the [index configuration](../configuration/index-config.md): |
| 19 | +- doc mapping (required) |
| 20 | +- indexing settings |
| 21 | +- search settings |
| 22 | +- retention policy |
| 23 | + |
| 24 | +You can manage templates using the [index template API](../reference/rest-api.md#index-template-api). |
| 25 | + |
| 26 | +## Config file format |
| 27 | + |
| 28 | +The index configuration format is YAML or JSON. When a key is absent from the configuration file, the default value is used. |
| 29 | +Here is a complete example: |
| 30 | + |
| 31 | +```yaml |
| 32 | +version: 0.9 # File format version. |
| 33 | + |
| 34 | +template_id: "hdfs-dev" |
| 35 | + |
| 36 | +index_root_uri: "s3://my-bucket/hdfs-dev/" |
| 37 | + |
| 38 | +description: "HDFS log management dev" |
| 39 | + |
| 40 | +index_id_patterns: |
| 41 | + - hdfs-dev-* |
| 42 | + - hdfs-staging-* |
| 43 | + |
| 44 | +priority: 100 |
| 45 | + |
| 46 | +doc_mapping: |
| 47 | + mode: lenient |
| 48 | + field_mappings: |
| 49 | + - name: timestamp |
| 50 | + type: datetime |
| 51 | + input_formats: |
| 52 | + - unix_timestamp |
| 53 | + output_format: unix_timestamp_secs |
| 54 | + fast_precision: seconds |
| 55 | + fast: true |
| 56 | + - name: severity_text |
| 57 | + type: text |
| 58 | + tokenizer: raw |
| 59 | + fast: |
| 60 | + - tokenizer: lowercase |
| 61 | + - name: body |
| 62 | + type: text |
| 63 | + tokenizer: default |
| 64 | + record: position |
| 65 | + - name: resource |
| 66 | + type: object |
| 67 | + field_mappings: |
| 68 | + - name: service |
| 69 | + type: text |
| 70 | + tokenizer: raw |
| 71 | + tag_fields: ["resource.service"] |
| 72 | + timestamp_field: timestamp |
| 73 | + index_field_presence: true |
| 74 | + |
| 75 | +search_settings: |
| 76 | + default_search_fields: [severity_text, body] |
| 77 | + |
| 78 | +retention: |
| 79 | + period: 90 days |
| 80 | + schedule: daily |
| 81 | +``` |
| 82 | +
|
| 83 | +## Template ID |
| 84 | +
|
| 85 | +The `template_id` is a string that uniquely identifies the index template within the metastore. It may only contain uppercase or lowercase ASCII letters, digits, hyphens (`-`), and underscores (`_`). It must start with a letter and contain at least 3 characters but no more than 255. |
| 86 | + |
| 87 | +## Description |
| 88 | + |
| 89 | +An optional string that describes what the index template is used for. |
| 90 | + |
| 91 | +## Index root uri |
| 92 | + |
| 93 | +The `index_root_uri` defines where the index files (also called splits) should be stored. |
| 94 | +This parameter expects a [storage uri](storage-config#storage-uris). |
| 95 | + |
| 96 | +The actual URI of the index is the path concatenation of the `index_root_uri` with the index id. |
| 97 | + |
| 98 | +If `index_root_uri` is not defined, the `default_index_root_uri` from [Quickwit's node config](node-config) will be used. |
| 99 | + |
| 100 | +## Index ID patterns |
| 101 | + |
| 102 | +`index_id_patterns` is a list of strings that define which indices should be created according to this template. Use [glob-like](https://en.wikipedia.org/wiki/Glob_(programming)) wildcard ( \* ) expressions to target indices that match a pattern: test\* or \*test or te\*t or \*test\*. You can also use negative patterns by prepending the hyphen `-` character. |
| 103 | + |
| 104 | +Patterns must obey the following rules: |
| 105 | +- It must follow the regex `^-?[a-zA-Z\*][a-zA-Z0-9-_\.\*]{0,254}$`. |
| 106 | +- It cannot contain consecutive asterisks (`*`). |
| 107 | +- If it does not contain an asterisk (`*`), the length must be greater than or equal to 3 characters. |
| 108 | + |
| 109 | +## Priority |
| 110 | + |
| 111 | +When multiple templates match a new index ID, the template with the highest `priority` is used to configure the index. |
0 commit comments