# Logstashでindexを作成する際のmapping

**URL:** <https://discuss.elastic.co/t/logstash-index-mapping/206134>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [November 1, 2019, 9:30am UTC](https://discuss.elastic.co/t/logstash-index-mapping/206134 "2019-11-01T09:30:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tsgkdt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsgkdt/32/39151_2.png) [@tsgkdt](https://discuss.elastic.co/u/tsgkdt)\
**Post date:** [November 2, 2019, 12:56pm UTC](https://discuss.elastic.co/t/logstash-index-mapping/206134/2 "2019-11-02T12:56:15Z")

</div>

Logstashのoutput-elasticsearchでデータを送ってIndexを作成する場合、そのときはtemplateを使ってmapping情報が構成されます。  
ですので、templateをどう指定できるかと考えた方が良いかと思います。

詳しくは以下を見てください。

> **[Elasticsearch output plugin | Logstash Reference \[8.11\] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-manage_template)**

> a template is applied to Elasticsearch during Logstash’s startup if one with the name `template_name` does not already exist.

manate\_template(初期値true)の他にテンプレートをどのように指定できるか、という観点では以下の３つがポイントになるかと思います。

- template
- template\_name
- template\_overwrite (上書きするならtrue デフォルト値はfalse)

これを踏まえますと、例えばこんな指定ができます。

```ruby
output {
    elasticsearch {
        hosts => ["https://localhost:9200"]
        index => "forum1102"
        template => "my_template.json"
        template_name => "my_template"
        template_overwrite => true
    }    
}

```

templateはjsonが書かれたファイルです。サンプルとしては、logstashの中のフォルダを探すと`elasticsearch-template-es7x.json`というファイルがあるかと思うので、そちらを参考にすると良いと思います。

---

_[View the full topic](https://discuss.elastic.co/t/logstash-index-mapping/206134)._
