# Json for setting up new indices

**URL:** <https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135>\
**Category:** Elasticsearch\
**Created:** [August 1, 2022, 3:36pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135 "2022-08-01T15:36:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhop](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jhop](https://discuss.elastic.co/u/jhop)\
**Post date:** [August 1, 2022, 3:36pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/1 "2022-08-01T15:36:30Z")

</div>

Sorry for the simple question but the documentation was not clear to me. I am using python to send data to elasticsearch.

Should we always define an index before using json specifying this index to populate elasticsearch? For example I saw these examples online:

`PUT my-index-000001 { "mappings": { "properties": { "date": { "type": "date" } } } } `

Then:

`PUT my-index-000001/_doc/3 { "date": 1420070400001 }`

Thanks in advance for any help you can offer.

- Jason

---

<div class="post-metadata">

**Author:** ![Ugo\_Sangiorgi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ugo_sangiorgi/32/146361_2.png) [@Ugo\_Sangiorgi](https://discuss.elastic.co/u/Ugo_Sangiorgi)\
**Post date:** [August 1, 2022, 4:49pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/2 "2022-08-01T16:49:39Z")

</div>

Hi, you can use index templates to define what mappings all indices starting with `my-index` will have: [Create or update index template API | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-template.html)

---

<div class="post-metadata">

**Author:** ![jhop](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jhop](https://discuss.elastic.co/u/jhop)\
**Post date:** [August 1, 2022, 4:55pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/3 "2022-08-01T16:55:57Z")

</div>

Do I always need to define the index template first separate template from the original json message to elasticsearch?

---

<div class="post-metadata">

**Author:** ![jhop](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jhop](https://discuss.elastic.co/u/jhop)\
**Post date:** [August 1, 2022, 5:03pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/4 "2022-08-01T17:03:55Z")

</div>

In other words will the first message define the index without creating an index template outright? Does it know how to set up a simple template on its own with the first message?

---

<div class="post-metadata">

**Author:** ![Ugo\_Sangiorgi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ugo_sangiorgi/32/146361_2.png) [@Ugo\_Sangiorgi](https://discuss.elastic.co/u/Ugo_Sangiorgi)\
**Post date:** [August 1, 2022, 5:13pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/5 "2022-08-01T17:13:42Z")

</div>

Elasticsearch has something called [Dynamic Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html) which creates a mapping for a field if it doesn't exists yet, and will try to guess what type it is - if the index itself also doesn't yet exists, Elasticsearch will also create it - it will not create an index template.

---

<div class="post-metadata">

**Author:** ![jhop](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jhop](https://discuss.elastic.co/u/jhop)\
**Post date:** [August 1, 2022, 5:16pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/6 "2022-08-01T17:16:46Z")

</div>

OK thank you! And thank you for supplying those links.

---

<div class="post-metadata">

**Author:** ![jhop](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jhop](https://discuss.elastic.co/u/jhop)\
**Post date:** [August 1, 2022, 5:30pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/7 "2022-08-01T17:30:48Z")

</div>

Sorry I am really new to elastic. Are there complete examples of ecs fields mixed with custom fields for both index templates and its corresponding json message? For example custom fields mixed with date and geo.location?

---

<div class="post-metadata">

**Author:** ![jhop](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jhop](https://discuss.elastic.co/u/jhop)\
**Post date:** [August 1, 2022, 10:09pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/8 "2022-08-01T22:09:30Z")

</div>

I found some examples. Thank you for your help.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 29, 2022, 10:09pm UTC](https://discuss.elastic.co/t/json-for-setting-up-new-indices/311135/9 "2022-08-29T22:09:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
