|
| 1 | +--- |
| 2 | +mapped_urls: |
| 3 | + - https://www.elastic.co/guide/en/elasticsearch/reference/current/index-mgmt.html#manage-index-templates |
| 4 | + - https://www.elastic.co/guide/en/serverless/current/index-management.html#index-management-manage-index-templates |
| 5 | +applies: |
| 6 | + stack: all |
| 7 | + serverless: all |
| 8 | + hosted: all |
| 9 | +--- |
| 10 | + |
| 11 | +# Manage index templates [manage-index-templates] |
| 12 | + |
| 13 | +Create, edit, clone, and delete your index templates in the **Index Templates** view. Changes made to an index template do not affect existing indices. |
| 14 | + |
| 15 | +:::{image} ../../../images/elasticsearch-reference-management-index-templates.png |
| 16 | +:alt: Index templates |
| 17 | +:class: screenshot |
| 18 | +::: |
| 19 | + |
| 20 | +In {{serverless-full}}, the default **logs** template uses the logsDB index mode to create a [logs data stream](../index-types/logsdb.md). |
| 21 | + |
| 22 | +If you don’t have any templates, you can create one using the **Create template** wizard. |
| 23 | + |
| 24 | +### Try it: Create an index template [_try_it_create_an_index_template] |
| 25 | + |
| 26 | +In this tutorial, you’ll create an index template and use it to configure two new indices. |
| 27 | + |
| 28 | +**Step 1. Add a name and index pattern** |
| 29 | + |
| 30 | +1. In the **Index Templates** view, open the **Create template** wizard. |
| 31 | + |
| 32 | + :::{image} ../../../images/elasticsearch-reference-management_index_create_wizard.png |
| 33 | + :alt: Create wizard |
| 34 | + :class: screenshot |
| 35 | + ::: |
| 36 | + |
| 37 | +2. In the **Name** field, enter `my-index-template`. |
| 38 | +3. Set **Index pattern** to `my-index-*` so the template matches any index with that index pattern. |
| 39 | +4. Leave **Data Stream**, **Priority**, **Version**, and **_meta field** blank or as-is. |
| 40 | + |
| 41 | +**Step 2. Add settings, mappings, and aliases** |
| 42 | + |
| 43 | +1. Add [component templates](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template) to your index template. |
| 44 | + |
| 45 | + Component templates are pre-configured sets of mappings, index settings, and aliases you can reuse across multiple index templates. Badges indicate whether a component template contains mappings (**M**), index settings (**S**), aliases (**A**), or a combination of the three. |
| 46 | + |
| 47 | + Component templates are optional. For this tutorial, do not add any component templates. |
| 48 | + |
| 49 | + :::{image} ../../../images/elasticsearch-reference-management_index_component_template.png |
| 50 | + :alt: Component templates page |
| 51 | + :class: screenshot |
| 52 | + ::: |
| 53 | + |
| 54 | +2. Define index settings. These are optional. For this tutorial, leave this section blank. |
| 55 | +3. Define a mapping that contains an [object](https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html) field named `geo` with a child [`geo_point`](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html) field named `coordinates`: |
| 56 | + |
| 57 | + :::{image} ../../../images/elasticsearch-reference-management-index-templates-mappings.png |
| 58 | + :alt: Mapped fields page |
| 59 | + :class: screenshot |
| 60 | + ::: |
| 61 | + |
| 62 | + Alternatively, you can click the **Load JSON** link and define the mapping as JSON: |
| 63 | + |
| 64 | + ```js |
| 65 | + { |
| 66 | + "properties": { |
| 67 | + "geo": { |
| 68 | + "properties": { |
| 69 | + "coordinates": { |
| 70 | + "type": "geo_point" |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + ``` |
| 77 | + |
| 78 | + You can create additional mapping configurations in the **Dynamic templates** and **Advanced options** tabs. For this tutorial, do not create any additional mappings. |
| 79 | + |
| 80 | +4. Define an alias named `my-index`: |
| 81 | + |
| 82 | + ```js |
| 83 | + { |
| 84 | + "my-index": {} |
| 85 | + } |
| 86 | + ``` |
| 87 | + |
| 88 | +5. On the review page, check the summary. If everything looks right, click **Create template**. |
| 89 | + |
| 90 | +**Step 3. Create new indices** |
| 91 | + |
| 92 | +You’re now ready to create new indices using your index template. |
| 93 | + |
| 94 | +1. Index the following documents to create two indices: `my-index-000001` and `my-index-000002`. |
| 95 | + |
| 96 | + ```console |
| 97 | + POST /my-index-000001/_doc |
| 98 | + { |
| 99 | + "@timestamp": "2019-05-18T15:57:27.541Z", |
| 100 | + "ip": "225.44.217.191", |
| 101 | + "extension": "jpg", |
| 102 | + "response": "200", |
| 103 | + "geo": { |
| 104 | + "coordinates": { |
| 105 | + "lat": 38.53146222, |
| 106 | + "lon": -121.7864906 |
| 107 | + } |
| 108 | + }, |
| 109 | + "url": "https://media-for-the-masses.theacademyofperformingartsandscience.org/uploads/charles-fullerton.jpg" |
| 110 | + } |
| 111 | +
|
| 112 | + POST /my-index-000002/_doc |
| 113 | + { |
| 114 | + "@timestamp": "2019-05-20T03:44:20.844Z", |
| 115 | + "ip": "198.247.165.49", |
| 116 | + "extension": "php", |
| 117 | + "response": "200", |
| 118 | + "geo": { |
| 119 | + "coordinates": { |
| 120 | + "lat": 37.13189556, |
| 121 | + "lon": -76.4929875 |
| 122 | + } |
| 123 | + }, |
| 124 | + "memory": 241720, |
| 125 | + "url": "https://theacademyofperformingartsandscience.org/people/type:astronauts/name:laurel-b-clark/profile" |
| 126 | + } |
| 127 | + ``` |
| 128 | + |
| 129 | +2. Use the [get index API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get) to view the configurations for the new indices. The indices were configured using the index template you created earlier. |
| 130 | + |
| 131 | + ```console |
| 132 | + GET /my-index-000001,my-index-000002 |
| 133 | + ``` |
0 commit comments